Net-informations.com

How to drop "Unnamed: 0" column from DataFrame

There are situations when an Unnamed: 0 column in pandas comes when you are reading CSV file . The simplest solution would be to read the "Unnamed: 0" column as the index. So, what you have to do is to specify an index_col=[0] argument to read_csv() function, then it reads in the first column as the index.

index_col=[0]

While you read csv file, if you set index_col=[0] you're explicitly stating to treat the first column as the index.

You can solve this issue by using index_col=0 in you read_csv() function.

index=False

In most cases, it is caused by your to_csv() having been saved along with an "Unnamed: 0" index. You could have avoided this mistakes in the first place by using "index=False" if the output CSV was created in DataFrame.


how to drop

Using regex

You can get ride of all Unnamed columns from your DataFrame by using regex.

Finally, you can simply delete that column using: del df['column_name'] .










net-informations.com (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About