How to write to csv without index

To write a Pandas DataFrame to a CSV file without the index, use the to_csv method and set the index parameter to False. For example this script is showing how to write to csv without index using example data and file:

import pandas as pd

df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df.to_csv('df.csv', index=False)

how to write to csv without index

This will write the contents of the DataFrame df to the file df.csv without including the index.

This Post Has One Comment

Leave a Reply