6.25 - Pandas series objects


In [1]:
import numpy as np

In [2]:
import pandas as pd

In [3]:
labels = ['a','b','c']
my_data = [10,20,30] # a list
arr = np.array(my_data) # an array
d = {'a':10,'b':20,'c':30}

In [9]:
pd.Series(my_data, labels) # passing pandas a list, defining labels


Out[9]:
a    10
b    20
c    30
dtype: int64

In [8]:
pd.Series(arr) # passing pandas an array, same thing


Out[8]:
0    10
1    20
2    30
dtype: int64

In [30]:
pd.Series(d) # whoa dictionaries are dope


Out[30]:
a    10
b    20
c    30
dtype: int64

In [31]:
pd.Series(data=['a','b','c'])[1]


Out[31]:
'b'

In [17]:
pd.Series(data=[sum,list,len]) # pandas can hold lots of shit


Out[17]:
0    <built-in function sum>
1              <type 'list'>
2    <built-in function len>
dtype: object

In [20]:
ser1 = pd.Series([1,2,3,4],['Williams','Bates','Bowdoin','Colby'])

In [21]:
ser2 = pd.Series([1,2,5,4],['Williams','Bates','Middlebury','Colby'])

In [22]:
ser1['Williams'] # numba one


Out[22]:
1

In [29]:
ser1 + ser2


Out[29]:
Bates         4.0
Bowdoin       NaN
Colby         8.0
Middlebury    NaN
Williams      2.0
dtype: float64

In [ ]: