A Few Days of Python: Importing CSV Files

Using the csv module

import csv
f = open('LP_Data.csv')
csv_f = csv.reader(f)

for row in csv_f:
  print row

Using the pandas module

import pandas as pd
df = pd.read_csv("LP_Data.csv")
df.head()

dat = pd.read_csv("LP_Data.csv", iterator=True, chunksize=100)
df = pd.concat(dat, ignore_index=True)
df.head()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s