econpy.org

Python for Economists

Read a CSV file into a Pandas DataFrame

Pandas is an awesome python library for data analysis. So many aspects of dealing with data are made so simple by pandas. The read_csv function takes a .csv as input and returns a pandas DataFrame. If your .csv file has the names of the columns in the first row, pandas will automatically label the indexes.

from pandas import read_csv
from urllib import urlopen
page = urlopen("http://econpy.pythonanywhere.com/ex/NFL_1979.csv")
df = read_csv(page)
print df
print df['Line']