You want to write a pandas dataframe to a csv file but when you do a index is getting added to the file and You want to avoid it.
Let’s read a dataset to explain it.
import pandas as pd url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/tesla_stock_prices.csv' df = pd.read_csv(url) df.head()
Now let’s try to write this dataframe to a csv file without any modifications.
Now, if I look into the csv file you will see that an index is getting added.
To avoid adding this index when writing a dataframe to a csv file, we can use the index=False argument.
Let’s try again and see the changes.
We can see that no index has been added this time.