Can I print a dataframe without row numbers?


I have a dataframe with 2 columns and I would like to save it on a CSV file only with the
2 columns , without the first column where there are the row numbers. How can I do that?
Thank you in advance.



You can use pandas’ to_csv method to write to a file and add index=False to remove the index column.

import pandas as pd

data = {'Name': ['John', 'Jane', 'Bob'], 'Age': [25, 30, 35]}
df = pd.DataFrame(data)

# Save the DataFrame to a CSV file without the index column
df.to_csv('output.csv', index=False)

Thank you again Bariskaraer1!

1 Like