Import modules


In [ ]:
import pandas as pd
import numpy as np
from pandas import DataFrame, Series

Working with Series


In [ ]:
x1 = Series([12,-5,7,15,-2])
x1

In [ ]:
x1.values

In [ ]:
x1.index

In [ ]:
x1[2]

In [ ]:
x1[[2,0,3]]

In [ ]:
x1[x1 < 0]

In [ ]:
print x1 * 2
print x1**2

Creating a Series from a dict


In [ ]:
sdata = {'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000, 'Utah': 5000}
x2 = Series(sdata)
x2

In [ ]:
states = ['California', 'Ohio', 'Oregon', 'Texas']
x3 = Series(sdata, index=states)
x3

In [ ]:
pd.isnull(x3)

In [ ]:
x3.dropna()

Plotting Series


In [ ]:
x2.plot()

Constructing DataFrames


In [ ]:
data = {'state' : ['California', 'Texas', 'Oregon', 'Ohio'],
        'population' : [38.3,26.4,3.9,11.5]}
f1 = DataFrame(data)
f1

In [ ]:
f2 = DataFrame(data,columns=['state','population'])
f2

In [ ]:
f3 = DataFrame(data,columns=['state','population','percent'])
f3

In [ ]:
data = {'state' : ['California', 'Texas', 'Oregon', 'Ohio'],
        'population' : [38.3,26.4,3.9,11.5],
        'percent' : [11.9,8.0,1.2,3.7]}
f4 = DataFrame(data,columns=['state','population','percent'])
f4

In [ ]:
f5 = DataFrame(data,columns=['state','population','percent'],
               index=[31,28,33,17])
f5

Accessing Cells


In [ ]:
f5.columns

In [ ]:
f5['population']

In [ ]:
f5.population

In [ ]:
f5.population > 20

In [ ]:
f5.loc[28,'state']

In [ ]:
f5[:2]

In [ ]:
f5[1:]

In [ ]:
f5.T

Sorting DataFrames


In [ ]:
f5.sort_index()

In [ ]:
f5.sort_index(by='state')

In [ ]:
f5.sum()

In [ ]:
f5.describe()

In [ ]:
f5.plot()

In [ ]: