In stack, overflow I see a lot of questions about removing index from dataframes made be to_csv
.
However, what I want to do is add an index to an already made csv file with no index.
How do we add an index to this csv with pandas?
CodePudding user response:
If you read csv file as dataframe, pandas will automatically generate index. You don't need to do something else.
So, just read it and write again as below
import pandas as pd
df = pd.read_csv("your_file.csv")
df.to_csv("your_file_to_save.csv")