How to read CSV File into Python using Pandas
In this post, we’ll go over how to import a CSV File into Python.
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: