Search⌘ K

Read CSV Data into Pandas DataFrames

Explore how to read CSV files into Pandas DataFrames while understanding the importance of data types and date parsing. Learn to use read_csv parameters to avoid common mistakes and improve data accuracy.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.5
from io import StringIO
import pandas as pd
csv_data = '''\
day,hits
2020-01-01,400
2020-02-02,800
2020-02-03,600
'''
df = pd.read_csv(StringIO(csv_data))
print(df['day'].dt.month.unique())

Explanation

The comma-separated values (CSV) format does not have a schema. Everything we read from it is a string. Pandas does a ...