* fondas
Ton das
Jmpoxtant data staudut o fandas(S eriu +t Satafaa
Siu, Jabs key alue otyeut on did.
Reading multiple lemuds em eiu. (uiny latfilbe
Swu wing liut Sidionay
ata fame
Head o t i methad o data fame
Catcgoi cal f Oxdinal daia
ata aam d uung
Muging , yoining s Concati naing methods
Concat o
myeo, Jen) and itwc,
data uing itetems U,
Itaating
itet ple
demotate handling rnissing dat in
Example that
naion.
pandw
Tandas
fand Satu dyotm (or) ttbon
-fandu skand tor
gote An alyss.
by Mekinnty in 208
IH Has (coted th ates
Hotkiny
fandas is a Pyth en libawt
onaly ing, oganin
pulafing data. item the
deaniy s tnon st s make
fands lan dean m y ate
Install Pandad
pandas uing pip
Inyt alliny
Handiing huqe amouat o data.
cleanempty st, wtfg data Rema dupli atu tau
42aping# visuali ing data wtth matplttb)
Atl ow doad atq
Meging 4 yoinng (daas baed on
3 uh a CSExd SQL, data bas ete.
Nus i ence.
Big tata f date sçne
feraing
Satafeame
like q calumn in a table
’A pandas Seiu acay hoding data anyt
’ Itis one d menn
Exa mple ¬D, |Erampe@pandus ad pd
pandas wpd
im pot poet
im pd
Sws (a)
2
le is speuli ed, the val are
gn ed ith th nded nu mhen Fat val bay'ndea9
slcond vadue hw indea () ee
This abd can be used -to
to aues aa Speiti ed vedsne.
Exumpl impett pandas au pd
q= Ci,1, 2]
b= p Seriea (a, inden C"x", ^y", "z"])
PnintCb)
2
22 7.
Seiwi
t Keyvalue objes a ojet dike a dieienay
You can alo
key val
hn cacating aq Seies.
al
progami impot panda
"days 2" 2002'days "rs
s 220),
q = " d a y": 0)
print (xeu t
200|
o|day i
20 2
daye 2 0 3
dty p e ' n t s 4
dum nts tem Seie:
* Readinq MulHfle
-loc! and ilo!
indeing
in a pandad ata Frare o
loc- (ltaton based indexca) It is used to sdlert
bs labd, Hhich mean yew Speiy the ind ez o cly tafrar
Oqme. i k ea Ce
Contair
- jlot (Intege. locottan based ind eu) . A + is used
sdet data by positorn,hiG
A h mean Jou speub tt
The
Dumeæcel indez.
Examplei mpot pandas as p
data 'A'o 'B'"20,'c'. 3 o,'8':4.3
.
q= pd- eeldata)
do qlo CA',
ilot =ailocco,2,31)
ovtput
2 3
4 4
40
type :intG4 A
A
dteint<)
4o
d+ype:intcy
-Seie Usng List and Drtona:
i mpo pandas a pd
pri nt(pd-suneas a) )
pìntCpd" SeiCb))
det
Ataame Is two dimensioD al aay obj ed:Seiu is
yike q col m,a Datafyame is the hle table t+that
a Dataframe
Containu roS Column.
he Data Frame Couist 3 omponnts
Ros
ExampluO-mpot pandas as pd
Co)
print (pd- Bataframe
outputiEmpty 9ataframe
Column:C]
Indez : c J
Example- impot pandos ad pd"Sai "Shiva
Tameeb"
data pgma" :
Myollnd '": C1o 2°,3o
atofra mt ( data))
1pit (pd.
names yllng
output
Sai
shivg
30
Kamerh
oDatotom
mthod method aie
Head t t i l theheadtail'
In pan das t
diaplog th biut
wd to
impotl pondan pd
data 'Name:[Sai, Sniva',Ra meeb
Age! :C2s, 3o,2 2,35]
Imark C9s,89,7S i
4=pd Datq Ya me (data)
pntea) pint (q head (2))
pri nt qtailC2))
output Nqrme Age
Sai 2 95
)shiva
Age
Rameh 22
Suruh 3S
Reoding Csv ler ulng pandag
A imple way to
CSW Gamma
Gamma epaled tilu
stoe a big data id Ja to
iu contaru plain tent sid ul
that can be sead by knon omd
ponda.
at CsV
I mpot pandas au pd
o|lno. agei nqme q pdaeod_csv ('[Link])
Sai pint ([Link] o)
24 Shivg ouput.
3 27 Ganuh olln age name
29
Rarmah 2
25
26
Shiva
27
29
Ganu
Rameh
t heading isen le
json5
Jsnis plain teat, but has thu (iava suipt bjet Nee)
In au encmple w ui touna o an objut
caled e uing a Tson e
dataj s ch'
datajso
iname":f"o":"Sq" shiva", '2":"9qngsh'?
rollns'!:"o" : 2),"": 22"'2:2a 234
secion'":"o":A""""B"2", "c3
lzogza m: impot pand as as pd
q= pd-ead-json('datajso)
pnnt(a) Hle.)
Pod pandas pd
=pd: ata rame(ID:Ci23},Name':C'sai',shive'
di pd Sotaframe({ 'ID Toju73)
prnt ( pd. mege (d{, -(2,3J,'Aqe':[25,30, ]3)
J2
Qutput
H
ID Nqme Age
2 Shivg 25
w
3 Raju 30
t Doining Data2a rmabak ed on Ce
on Commm Dame olum)
impot pandau as pd
dyi= pd Satafaa
d e= pd- atafagme
m('N ame' :Csai aj]'Age:esi313)
'salay': [soo, 4oo,index-[sail}
print (dtijoin(de ( roj
gutpud' Name Age Salay
Sa 25 Gooo
olum
t teesling dala (usimg ioitero
Concalinalheg Dalal camea
impot pandas au pd
apd Datafvame({ 'TD':[I,,3],'Narme':[sa''shiraj.,
At pd- )
DotafT0me(f'p':[4SiJNarme' :frameb 'suvesh'
pont ( pd- Concat ( Ed
A2], ignoe=i nd exharish"])
= True))
oulputi
Sa
2 Shiv
rajy
Yames
6
Sureb
haush
*Example -that demnstratee handling missing dat in
pandas using va?
Vaas untior
impot pandas a pd
impset Dumpy u np
datq 'Tp':[i2,
np-nan4}
'Name':['s'am &b!, np-nan 'raj,
Age': [2s .[Link] ,2213J
a= pd- Dataframe (dati)
pint (q-isnull() tt it will display tue in plae°nu
int(a dapna 0)ttit iaill dup cormplede w th mising ral
pnint(a-na# Gling missing vaw with nmian
pant ([Link])# Tntepolating missi ng vele
etim ating missing
data.
shape (Tout, Column)
lumnd : column table
d index : Ro \abels
- d3typl:9ata ty pes o each olumn
-d. valy! Humpy awag o data
Accesing ous wing labele f posit o.
Example:
- Reindee
dteindee CCi,o])
t a p Ent ded Eniry
-S2op Glumn
d-dop ('Age',ais=)
[Link]()
Selet Golumn:
dC'Nane']
-Goditiond Slecticn
Bshape (roud, Column)
A calumat olumn table
dindex : Row labels
d}+ypes 9ata ty pe o each olumn
J valuey' Humy avay daka
Accesing Tows uing labele s poiton.
Example:
Reinde
ptnd
82cp Gl umn
di-dop ('Aqe', qis=)
Slat Calumn:
dC'Narne']
-Gnditiond sleticn
9ata Aign ment:Automati aly alligra
duing epenati onu
-Randem Sample"
d Sample (1)
Sortng
di sot_alues (by= 'Age)
- d d ucaibec: Staist cal Summy
- d . mean c): Mean Value
d. count (): Noh -nul count
- dt min D d max : nin|rlaz values.
- dtstd O, di. va(): std- devi attor and vaian
*|d4Cma]-maxt)
9ata Aígn mnt: Automaticay aligru
duing operati onu
Rando Sample
d Sarmple ()
Sortng
d sotvalues (bg='Age)
[Link])
- dt deuaibec): Stahsti ce Summay
mean C): t7
ean Va|yes
d count ): Noh -n l Count
d min [Link] Min Max value.
d-st4 CO, dt. var(): std- deviatton andvau ane
ex.
friat+|34Cmasw]-max))
ata Visu alizati o in
Datat rames
ala frame ae table like
data stzudue in Pandas
Panda integiade l wth Matplotlib 4
Visui att'o Seabon aa
- You can call -plot c) dity on
ata frame Souies
Example:
impot pandas aJ pd
impet madplot lib. py plet as plt
df= pd- atafrarn e(Ye :2620, 202l,
2022J|
Sdu':lo, Iso 201)
df- plot (x='Yeas', y'sdu, kind=line!
pt HHe(Yealy Salu)
pttti
plt-xlabel (Yea')
plt-ylabel(salu)
plt - shew c)
t But in ibzajeu:
loo levd, Heible powul pletting ibny
- Govd to Czuting cutors plots
Basic Syntax
irnpod mat plt lib p9plot as plt
[Link](9 pt. HHecTite")
plt- lab ("t)*-qs
plt-ylasel("y- qds")
plt shot)
) Uaity-’ Eosue
thevisuaiat Garnmunicateu mosage ptt
) Simplicity -> Av oid
unnesu dmut kep the plot clean.
3) Afzpai ad en ug chotte the
9 Accway’ Kepxent data ight type o plotto thu data
) Grstehiy tuthully wtthod distoti o
coruit ent scale,colop labuling
nm n plot type visvalht
Rlot Tup
Line Plot
Baz Chazt
shoing thetndd avee tima
Carnpaung quartHu aou catg odu
Histog2arn glsplaying istibutton in yatte
ConH ny dadt otttet.
Summaizìng distibution wing quatlu
Scattaflot’ Epl oung xlatiou bips bhutts tu
numwcal vewablu
Heodmap’ Shouing Coudation matice ot date
(
Pie chat’ densites.
Shouing paopotioh o cadegojs
ioine Plot Vis ualing oi stibutn sfaobobiltby
density.
Paie Plot ’ Mulip le Scattr plots
shoung pairwide
Adatioruips
mplea dJ mpk-line (Basic ine Plot)
npot mad plotlib py plot au plt
=2,3,4
plt plot(ai8)
plt itBe(1Basic Lines Plt")
plt xlabd ("* ois)
PIt label (y-qi>)
plt9-ud (Tru)
Plt shoo
2. Ban Chat
This ba hat shens va l e euoS calgoia.
impo maplotlib ad plt
Catgoiel = C'A',8', 'c,D'
Valuee C3,7, S
plt"ba Ccategouu vad)
plt He(Bau chat Exampl)
pitxlabl (" Cateqo24)
plt: ylabd ("Value ')
plt show)
3> Histogram egueny diabutien
This hìsto giam shews
andem data.
i mpot matplotli b au plt
impot numpy a np
data= [Link] (looa)
edgeca Jor= ba
Plt- hi st (data bìnd3o, Colo=\skyblue black
plt He(" Histugam Example")
rlt:xlabl("Value)
pitylabd("Faqueny")
[Link] ()
4) Scatta Plol
This plot shous scattu o points.
Impet matpltlib-pyplot ad plt
X= [s,7, 87,2, 17]
5 93,36, 87, 83i10o, %6]
plts catt e Caiy)
plt- titte("s cattPl)
plt alab("X-valu)
plt- ylabd("[Link])
s> ie chaat
This piechat displayo pauts * a whote.
impott mat plotli b- p9 plort ad plt
|abs= 'Rthon ', 'Java',' Ctt', 'Ruby'
size= C215, 13 o, 245, 2\0
plt piel si zdilabls=labds,qutoptz
plt HHe("fie chat Examnple ") )-\+11.'
plt: qi(equal')
pltshoo()
eabo
Bilt on top o Matplotlib
High levd intatate for statt st ca g2aphia.
Automati cally bandlu pandas atafrarmu adds qesthetia
undions
sns. lineplt c)
Sns. bplet)
’ Sns. boplot
’ Sns-heatmap
Sns- papl otc)
Examples
impot subon as Sns
impot pandas as pd
df Sns. load~d ataut (tips')
[Link] (z=day',=otal-bill',dota d)
pltiHe('Boxp lot o Total Bi1| by Day)
plt-she)