Python Forum
Pandas dataframe without index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas dataframe without index
#1
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
Reply
#2
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.
tgottsc1 likes this post
Reply
#3
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
Reply
#4
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 723 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Question on pandas.dataframe merging two colums shomikc 4 814 Jun-29-2023, 11:30 AM
Last Post: snippsat
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,553 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  help how to get size of pandas dataframe into MB\GB mg24 1 2,332 Jan-28-2023, 01:23 PM
Last Post: snippsat
  pandas dataframe into csv .... exponent issue mg24 10 1,761 Jan-20-2023, 08:15 PM
Last Post: deanhystad
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 823 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,739 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  "Vlookup" in pandas dataframe doug2019 3 1,840 May-09-2022, 01:35 PM
Last Post: snippsat
  Increase the speed of a python loop over a pandas dataframe mcva 0 1,310 Jan-21-2022, 06:24 PM
Last Post: mcva
  for loop in dataframe in pandas Paulman 7 2,742 Dec-02-2021, 12:15 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020