Pandas Flashcards
series
array with index
Example: create a series
obj = Series([4, 7, -5, 3], index = [‘d’, ‘b’, ‘a’, ‘c’])
find obj value
obj.values
find obj index
obj.index
Find value for index ‘a’ and index ‘c’,’a’,’d’
- obj[‘a’]
2. obj[[‘c’, ‘a’, ‘d’]]
Series vs. dict
Series is a fixed-length, ordered dict
Check if index ‘b’ exists in obj
‘b’ in obj
Create series from dict sdata
obj = Series (sdata)
Check if the value exits (or not exits) for the series obj
- pd.isnull(obj)
2. pd.notnull(obj)
Create name attributes for Series object obj and its index
- obj.name = ‘population’
2. obj.index.name = ‘state’
Most common ways to construct DataFrame
- from a dict of equal-length lists e.g. if data is a dict object, then DataFrame object frame = DataFrame(data)
- NumPy arrays, e.g. if data is a NumPy array, DataFrame(data, columns=[‘year’, ‘state’, ‘pop’]
How to retrieve a column from DataFrame as a Series
- dict-like notation: frame[‘state’]
2. by attribute. frame.year
retrieve a row from DAta Frame object frame with index ‘three’
frame.ix[‘three’]
delete a column ‘eastern’ from DataFrame object frame
del frame[‘eastern’]
Is the index objects mutable?
No, so Index objects c an be safely shared among data structures