Pandas Pt 1 (Wk 4 UCSD) Flashcards
What is pandas
a library built on numpy, with flexible data structures
how to use the pandas library
import pandas as pd
What is a series in pandas
A one dimensional dict like structure (index, values), that allows for diff data types, and works w/ most numpy functions
how to declare a series
ser = pd.series( data=[ values], index = [indices] ) (don’t have to say data = and index =)
print the in dices of a series
print (ser.index)
retrieve data from a series at a given index ‘Bob’
ser[ ‘Bob’ ] or ser.loc[ ‘Bob’ ]
retrieve multiple data points in a series with index values
ser[ [ ‘bob’, ‘nancy’ ] ]
retrieve data from series by indexing on position
ser[ [ 1, 2, 3 ] ]
test if a given index is present in a series
‘bob’ in ser»_space; returns boolean
can you perform operations on a series, like you can with arrays?
yes. ser * 2 multiplies all values in series by 2
What is a dataframe
it’s like a 2d series, where indices become row names, and name of each series becomes col names
How do you create a dictionary with multiple sets of series, which you could then assign to a dataframe?
d = {‘one’ : pd.Series([values], index=[indices]),
‘two’ : pd.Series([values], index=[indices])}
create a dataframe using a dictionary of series
pd_dataframe = pd. dataframe(dict_of_series)
retrieve the row names from a dataframe
df.index
retrieve the column names from a dataframe
df.columns