Python Forum

Full Version: Pandas dataframe without index
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I have a basic question about dataframes. However, my Google search has not yielded the desired results so far. I have data stored in a pandas.core.frame.DataFrame called data_stocks. When I type data_stocks and press CTRL + Enter, a simple DataFrame table is created. This table shows an index column that I would like to get rid of without changing the format of the table (that is, without converting the table to a different format).

Google search results recommended printing the table and using (index=false), however this changes the layout of the table, which is not the intention.

I would be grateful for any help!

Best regards!

Tim
Are you just trying to hide the index from display, or do you have a reason to eliminate the index entirely (and why?) If just trying to hide it, make a dataframe from a slice of the original and display that.
I should have tried before posting. Playing with this, I think your best bet is
df.reset_index(drop=True, inplace=True)
Though you still see the row numbers when you display
hth
From script.
print(df.to_string(index=False))
In NoteBook.
df.head().style.hide_index()
[Image: KorLwI.png]
More normal to remove index when want save a DataFrame to different format.
df.to_csv(index=False) 
df.to_html(index=False)