Python Pandas Cheat Sheet
by LasseBoe (Lasse1618) via cheatography.com/110079/cs/21581/
STOPPED FILLING AT LECTURE 6 LINE Basic Dataframe Analysis (cont) Label-based indexing with .loc / .iloc
122 (cont)
df.plot.scat‐ scatterplot
ter(x = df.loc[:, 'col1' ] column with t/f whether
'name', y = == 'name' entry in col1 is name
Basics 'name')
%matplotlib inline plots into notebook pd.plotti‐ multiple scatterplots df.iloc[3:-1, 2:] [rows, columns]
df = pd.read_c‐ loads dataframe ng.scatte‐ df.iloc[:, [3, 1]] columns with index 3 & 1
sv( path, r_matrix(df)
.loc is label based, .iloc is integer index
index_col pd.plotti‐ lines drawn connecting
based
='name') ng.parall‐ dimensions of an entry
df.head() el_coordi‐
Series
nates(df,
df.tail()
'name') s1 = pd.Series([1, 2, creates a pandas
df.values 3], index=['a', 'b', series
df['col_n‐ returns list of singled entries
df.plot() 'c'])
ame'].u‐
df.plot(style='.') s1.add(s2, fill_value=0)
nique
df.index returns row indexes s.isnull() ; s.notnull()
pd.get_du‐ dummie column (0 or 1) that
df[col].loc[ index] returns value with mmies(df, indicates whether the entry s.dropna() drops all rows with
given column and columns= in another column is a missing values
index ['Name']) certain entry s.fillna(x)
df.loc[:, 'col_n+1'] referring to a col that np.ran‐ selects random set s = pd.DataFrame‐ Best way to define
=x doesn't exist creates a dom.ch‐ ({'Size':s1, 'Weigh‐ dataframe out of
new one oice(n, x, t':s2}) series:
replace=f‐ Give dict out of
Basic Dataframe Analysis alse) columns
df.isnull() returns bool np.setdif‐ New set with only the 'e' in s1 returns bool
df[.isnull().sum returns sum of trues f1d(set_1, differing entries
s.name = 'str' names series
set_2)
df.isnull().any checks whether there is s.index.name = 'str' names index
a true df.to_‐ gives array of entries
If s doesn't exist, this
numpy()
df[col].max() creates a df
df[col].min() s.columns['Red', 'Green']
Working with a Dataframe
df[col].idxmax() s.columns.name = 'Color'
df['col1'] == x bool if entry is x
df[col].idxmin() s.reindex[('m', 'n', ffill = forward fill
df[df == x] = y replace all values of a kind 'o'], method = 'ffill')
df[col].median()
df[col].mean() Label-based indexing with .loc / .iloc
df[col].des‐ gives statistic analysis
df.loc[rowindex, columnname]
cribe()
df.loc[3, col1] 3rd entry of 1st
df[col].qua‐ 50% quantile df.loc[3:6, ['col1', column
ntile(.5) 'col2']]
df.boxplot(by = boxplot grouped by
'col') column
df.hist(bins = 20) histogram in 20 bars
By LasseBoe (Lasse1618) Not published yet. Sponsored by ApolloPad.com
cheatography.com/lasse1618/ Last updated 23rd November, 2020. Everyone has a novel in them. Finish
Page 1 of 1. Yours!
https://apollopad.com