Q DATAQUEST
KEY
\W6'l so shorthand in thi cheat shoot
4 -A pons Dataframe objet
'5-Apandas Seis object
.read_csv( Filename) From CSV fle
é.read_table(ilenane)-Fromadeliited txt
‘leks T¥
.read_excel(f1lenane) -Foman Exe fle
.read_sql(query, connection object)
Reads oma SQL tbleldatabase
pd read_json(Js0n_string)-Reads rama SON
read htsl (url) -Pases an html URL tng ot
sont tables toi of datas
1. read_eLipboard() Takes the contents of your
‘ipbowrd ang paseo read_table()
é.0ntaFrane(dict)-Froma ct kay for
lars amas vals or dat a its
4F.to_csu(#lLename) Whites oa C5 fle
Gf. to_excel(Flenane) -Witestoan Eel le
4F-t0_sal(table_nane, connection object)
wees t050L table
4F.to_json(FiLenane) -Wites toa fin JSON
Gf. to_tn (LLenane) Saves asan HTL table
Gf. t0_eLipboard() -Whtesto the cpboad
Us
.DataFrane(ap-randon.rand(20,5))-5
é.sSeries(ay_Uist)-Cratesa series rom a
terablomy list
AF index = pd.date_range(’900/1/30",
pertodsedf.shape[@]) -Addsa date index
VIEWING/INSPECTING DATA
4f head) Fist mows the Oatafame
4F.2a11(0) -Lastnrowsofthe DataFame
6F. shape - Number of rows and cols
4 AnFo() Index, Datatype and Memery
Gf. describe()- Summary satisis for numeri
‘s.value_counts(éropna=False) Views unique
values and counts
4f. apply(po.Sertes.value_counts) - Unique
Values and counts forallcolns
Data Science Cheat Sheet
IMPORTS
Inmpor these to start
inport pandas as pa
inport numpy as mp
[col] - Rerum column with abel ol as Sves
GF{{eo12, €ol2)] -RetunsColumnsasanew
Bataframe
5: 10c(6] Selection by postion
5: oe{@} Selection by index
4 A20e(6, :]-Fastiow
4 A20e{0,0] Fist clement fist calum
GF colums » ['2',"B',"€"]-Renames columns
i fsnu1() Check for rul Values Rete
Been ray
natn ()- Opposite of. Ssn411()
4 dropna() -Dropsalrows that contain null
‘dues
4f dropna(axis=1) -Drops al corms that
4 dropna anise, threshen) -Dropsalloms
4 #8114 (3) -Replce rl values thx
-.f411na(s.mean() Replace all valve ith
themean mean can be repliced wth almost
ny fumetion fromthe tates ection)
-astype( float) -Convers the datatype ofthe
series to float
-replace(4, “one') Replaces al aes equ to
ath one
-replace( [2,3], [one "theee*]}) Replaces
f renane(colunns=Lanbda x: x + 2) Mass
4 renane (coluanss{'o14_na
rane") Selective renaming
=F set_index( column one
0.5) -Rowswherethe col column
GF{(aF{eot] > 0.5) & (aF{eot] < @.7)1
7 > col > 0.5
4F.sort_values(col1) Sorts vlvsby colin
ending order
Gf. sort_values(col2,ascending=False) Sorts
‘values by colzin descending order
4f-sort_values({colt,¢012],
‘ascendinge[True,False]} -Sortsvaluesby
Pandas
{6 groupby (col) Reta group abject for
vals rom one clunn