In [5]:
%matplotlib inline
from pandas import Series, DataFrame
import pandas as pd
import numpy as np

In [2]:
obj = Series([4,7,-5,3])

In [3]:
obj


Out[3]:
0    4
1    7
2   -5
3    3
dtype: int64

In [8]:
type(obj.values)


Out[8]:
numpy.ndarray

In [9]:
obj2 = Series([4,7,-5,3], index=['d','b','a','c'])

In [10]:
obj2


Out[10]:
d    4
b    7
a   -5
c    3
dtype: int64

In [11]:
obj2.index


Out[11]:
Index([u'd', u'b', u'a', u'c'], dtype='object')

In [12]:
# DataFrame
data = {'state' : ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'], 
       'year':[2000, 2001, 2002, 2001, 2002], 
       'pop':[1.5,1.7,3.6,2.4,2.9]}
frame = DataFrame(data)

In [13]:
frame


Out[13]:
pop state year
0 1.5 Ohio 2000
1 1.7 Ohio 2001
2 3.6 Ohio 2002
3 2.4 Nevada 2001
4 2.9 Nevada 2002

In [16]:
frame2 = DataFrame(data, columns=['year','state','pop','debt'], index=['one','two','three','four','five'])

In [17]:
frame2


Out[17]:
year state pop debt
one 2000 Ohio 1.5 NaN
two 2001 Ohio 1.7 NaN
three 2002 Ohio 3.6 NaN
four 2001 Nevada 2.4 NaN
five 2002 Nevada 2.9 NaN

In [20]:
frame2['state']


Out[20]:
one        Ohio
two        Ohio
three      Ohio
four     Nevada
five     Nevada
Name: state, dtype: object

In [23]:
frame2.ix['three']


Out[23]:
year     2002
state    Ohio
pop       3.6
debt      NaN
Name: three, dtype: object

In [25]:
frame2.T['three'].T


Out[25]:
year     2002
state    Ohio
pop       3.6
debt      NaN
Name: three, dtype: object

In [40]:
frame2['debt']=16.5

In [41]:
frame2


Out[41]:
year state pop debt
one 2000 Ohio 1.5 16.5
two 2001 Ohio 1.7 16.5
three 2002 Ohio 3.6 16.5
four 2001 Nevada 2.4 16.5
five 2002 Nevada 2.9 16.5

In [49]:
val = Series([20],index=['three'])
frame2['debt']=val
frame2


Out[49]:
year state pop debt
one 2000 Ohio 1.5 NaN
two 2001 Ohio 1.7 NaN
three 2002 Ohio 3.6 20
four 2001 Nevada 2.4 NaN
five 2002 Nevada 2.9 NaN

In [55]:
# Copy Series from frame, modify and set back 
# There's probably a better way to do this but I keep getting the copy of slice warning...
val = frame2['debt'].copy()
val[np.isnan(val.values)] = 16.5
frame2['debt'] = val

In [56]:
frame2


Out[56]:
year state pop debt
one 2000 Ohio 1.5 16.5
two 2001 Ohio 1.7 16.5
three 2002 Ohio 3.6 20.0
four 2001 Nevada 2.4 16.5
five 2002 Nevada 2.9 16.5

In [65]:
f = lambda x: Series([x.min(),x.max()], index=['min','max'])
frame2.apply(f)


Out[65]:
year state pop debt
min 2000 Nevada 1.5 16.5
max 2002 Ohio 3.6 20.0

In [72]:
frame2.ix[1]


Out[72]:
year     2001
state    Ohio
pop       1.7
debt     16.5
Name: two, dtype: object

In [ ]: