Export & Save pandas DataFrame to CSV File without Index in Python (Example Code)

This article explains how to convert a pandas DataFrame to a CSV file without index numbers in the Python programming language.

Preparing the Example

import pandas as pd                       # Import pandas library in Python
my_df = pd.DataFrame({'A':range(0, 5),    # Construct pandas DataFrame in Python
                      'B':['x', 'y', 'x', 'x', 'y'],
                      'C':range(15, 10, - 1)})
print(my_df)
#    A  B   C
# 0  0  x  15
# 1  1  y  14
# 2  2  x  13
# 3  3  x  12
# 4  4  y  11

Example: Ignore Index when Exporting pandas DataFrame as CSV File

data.to_csv('my_df.csv',                  # Saving pandas DataFrame as CSV
            index = False)

Further Resources & Related Articles

Have a look at the following Python tutorials. They explain topics such as indices, data inspection, and naming data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top