How to read CSV File into Python using Pandas

In this post, we’ll go over how to import a CSV File into Python.

Barney H.
Towards Data Science

Photo by AbsolutVision on Unsplash

Short Answer

The easiest way to do this :

import pandas as pddf = pd.read_csv ('file_name.csv')
print(df)

If you want to import a subset of columns, simply addusecols=['column_name'];

pd.read_csv('file_name.csv', usecols= ['column_name1','column_name2'])

If you want to use another separator, simply add sep='\t' ; Default separator is ',' .

pd.read_csv('file_name.csv', sep='\t')

Recap on Pandas DataFrame

Pandas DataFrames is an excel like data structure with labeled axes (rows and columns). Here is an example of pandas DataFrame that we will use as an example below:

Code to generate DataFrame:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (3)

Several typos here. Your example of importing from CSV with no header should be pd.read_csv, not df, no?

Excuse me, how can I import specific columns to dataframe together with 'header=None'?
cause when i used in the same brackets with 'usecols' nothing comes out

I would’ve liked you to write more about how to import a .CSV file from computer, specifying path and everything. This always confuses me.