Read CSV File without Unnamed Index Column in Python (Example)
In this article you’ll learn how to load a CSV file without an unnamed index column in Python programming.
The article consists of these contents:
It’s time to dive into the example:
Exemplifying Data & Software Libraries
We first need to load the pandas library to Python:
import pandas as pd # Import pandas library in Python |
import pandas as pd # Import pandas library in Python
The following data is used as a basis for this Python programming tutorial:
data = pd.DataFrame({'x1':range(105, 113), # Create pandas DataFrame 'x2':['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], 'x3':[9, 2, 7, 3, 3, 1, 1, 8], 'x4':range(26, 18, - 1)}) |
data = pd.DataFrame({'x1':range(105, 113), # Create pandas DataFrame 'x2':['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], 'x3':[9, 2, 7, 3, 3, 1, 1, 8], 'x4':range(26, 18, - 1)})
Let’s export our data to create an exemplifying CSV file in our working directory
data.to_csv('data.csv') # Export pandas DataFrame |
data.to_csv('data.csv') # Export pandas DataFrame
After running the previous Python code, you will find a new CSV file on your computer. We will use this CSV file for the following example.
Example: Import CSV File without Unnamed Index Column
The following Python code explains how to read a CSV file as a pandas DataFrame. In this DataFrame, the unnamed index column of the CSV file should be ignored.
For this task, we have to specify the index_col argument of the read.csv function to [0] as shown in the following Python syntax:
data_import = pd.read_csv('data.csv', # Read pandas DataFrame from CSV index_col = [0]) print(data_import) # Print imported pandas DataFrame |
data_import = pd.read_csv('data.csv', # Read pandas DataFrame from CSV index_col = [0]) print(data_import) # Print imported pandas DataFrame
Have a look at the table that got returned by the previous Python syntax. It shows that our imported data comprises eight rows and four columns. You can also see that we have created a pandas DataFrame without showing an unnamed index column.
Video, Further Resources & Summary
Do you want to know more about the loading of a CSV file without unnamed index column as a pandas DataFrame? Then I can recommend having a look at the following video which I have published on my YouTube channel. I explain the Python programming syntax of this tutorial in the video:
The YouTube video will be added soon.
In addition, you might read some of the related tutorials on my website.
- Read CSV File as pandas DataFrame in Python
- Write pandas DataFrame to CSV File without Index
- Write pandas DataFrame to CSV File with & without Header
- Get Index of Column in pandas DataFrame in Python
- Convert Index to Column of pandas DataFrame in Python
- Rename Column of pandas DataFrame by Index in Python
- Drop pandas DataFrame Column by Index in Python
- Basic Course for the pandas Library in Python
- Introduction to Python Programming
Summary: In this article you have learned how to load a CSV file without unnamed index column as a pandas DataFrame in Python. Let me know in the comments section, in case you have further comments or questions.