Import CSV File & Ignore Unnamed Index Column in Python (Example Code)

In this article you’ll learn how to load a CSV file without unnamed index column as a pandas DataFrame in the Python programming language.

Setting up the Example

import pandas as pd                                     # Load pandas library
my_df = pd.DataFrame({'A':range(100, 105),              # Construct new pandas DataFrame
                      'B':[9, 3, 7, 1, 2],
                      'C':['a', 'f', 'c', 'f', 'f'],
                      'D':range(35, 30, - 1)})
my_df.to_csv('my_df.csv')                               # Write exemplifying DataFrame to folder

Example: Read pandas DataFrame from CSV File & Ignore Unnamed Index Column

my_df_load = pd.read_csv('my_df.csv', index_col = [0])  # Import CSV & print output
print(my_df_load)
#      A  B  C   D
# 0  100  9  a  35
# 1  101  3  f  34
# 2  102  7  c  33
# 3  103  1  f  32
# 4  104  2  f  31

Leave a Reply

Your email address will not be published.

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