How to avoid Python/Pandas creating an index in a saved csv?
There are 2 ways that to handle matters wherever we have a tendency to don’t wish the index to be keep in csv file.
As others have explicit you’ll use index=False whereas saving your
dataframe to csv file.
Otherwise you will save your dataframe because it is with Associate in Nursing index, and whereasreading you only drop the column unknown zero containing your previous index.Simple!
df.to_csv(' file_name.csv ') df_new = metal.read_csv('file_name.csv').drop(['unnamed 0'],axis=1)
The one of the best answer is by keeping column as index.
pd.read_csv('filename.csv', index_col='Unnamed: 0')