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

Pd.read_csv(io.StringIO(df.to_csv()), index_col=) You can solve this issue by using index_col=0 in you read_csv() function. While you read csv file, if you set index_col= you're explicitly stating to treat the first column as the index.ĭf = pd.DataFrame(np.random.randn(5,3), columns=list('xyz')) So, what you have to do is to specify an index_col= argument to read_csv() function, then it reads in the first column as the index.

The simplest solution would be to read the "Unnamed: 0" column as the index. There are situations when an Unnamed: 0 column in pandas comes when you are reading CSV file. How to drop "Unnamed: 0" column from DataFrame
