Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how should i read a csv file without the 'unnamed' row with pandas? [duplicate]

Tags:

python

pandas

csv

I am writing to a .csv file with:

my_data_frame.to_cav("some_path")

When trying to read the file with:

pd.read_csv("some_path")

I can tell that an unnamed column was added. How can i fix that?

like image 485
avicohen Avatar asked May 02 '16 07:05

avicohen


People also ask

How can I avoid unnamed zero pandas?

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.


1 Answers

to_csv() writes an index per default, so you can either disable index when saving your CSV:

df.to_csv('file.csv', index=False)

or specify an index column when reading:

df = pd.read_csv('file.csv', index_col=0)
like image 50
MaxU - stop WAR against UA Avatar answered Sep 23 '22 18:09

MaxU - stop WAR against UA