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?
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With