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()
Advertisements