UNIT- V
which stores JAopup af elements
Aray is an object
Aray- diferenee
betoeen Liyt
J. The main
Same,type. (n a
elem ents seperuted
sÇperated
stores-the heterogenous elem ents
Lt
is, honoe meaus elemo
i e u s eemae
cand aay the homoge
stores
s tores
C] an d amay
bycomnain
Seperated by Space in 3.
modale eor)
third pty module.
external
Neumif ir a and mange. mutt
mange.
Numty and
cucdto
uwcd tO ProCeSS
process
i
Prthon, which
Cnear alqebra Operálonj
tn aa
in lnear algebra operátlong
andLo penfomm
aray depends
dmertiomal
the
t he operätim
operättms
most o
ef
Unear algebra
Jn
amays whtlch
which
enEwo Cor) multf limernsTonal Numerieal Pthan
Rthon ,
Numerical
s t a n d s k r
Nem Pr
NemPy ppli caton a
a-ffool
lolowws
s
pip appli caiton
instal sing
excustrely
Plp fnstall nump
n-dfmertional frray. NumPy
standsfor
Ndavray co k sf
oorrk -a rstte
fa err
Ndanay ndarbaY,
ndadday,
ohich
cohtch o
Calle d as
a s
Called
an aray
CAeats
a r a y s are.
are
arrays
Lhar L t single
sinyle
dimentional
dimerittonal
-D aray - elemet n -th
GAeating how oL
ne
Aepresernts
cohich
he aay S
form f ist elemvs])
homgEnav
np. array
(E
z
a r name
Symtax
EX import numpy as npP.
arl= np. aray ( [ 10, 20, 30, 40J
print (arr1)
out 10 20 30 OJ
pnt Cdrrl drtppe
outdou nd array' sEomal a r a y s
are
Toodmen
(olum).
cArating 2-D Oarray and
one
Yows
Yas
a Y r a ys tuwo
dn t w o
epresents
avrays
twhich
aay,
OrTay s.
1-D
CUray o
r)
a s np
npP
numpy as
EXEmport
(IL*, 6J,
anra= [Link]
C3)
print (an-)
CCi63
ats
C3ST3 array,
Stens O
dimenstons
dmen
o
p o f
Of-
i e p r e S e T t s
c) Acpvefentr
Acpmefentr
t
tYPr
ndim o
to
ndim t ) - uUe
edd
ctio)
)-t«pe
() -fun
tYPe
ne d
sstg
ca
oksed Sntop :tyrlarray _name)
numpy as np
import
Ey
EX
anrl = np. aray ( [ L, 4, 6, )
print (arrl)
out [1.4 6 U
anay is
amay ts
an aray
Two Dimen Sina
DimenSirnal
scating
2-D Cay
t am aay 4af aYTays.
arayS.
within an aray. ie
asTP
tmpor umpy
EX
4,5], [; 7?, t7",] )
np. array ([ L2,
ary
Print (arr )
L L2 4 5J,
f6 7&1,
Some
extra
extra data typu
data-typs
hau
NmPy
Num Py tee f o r
Data tpes ctor.
ctur. Wee
ewith
d a t a t u p e s w i t h
a ne
One chara
Ac-fer t o
and efc.
unsigned
nteger.
v-for
mtege ,
intege
Aata-ty pe
data ty pes
ntn NomPy,
NomP,
Shouasthe
Lst
Bclo
Entege
b bcolean
U n s i g n e d nteges
f - floa
float
-
Cmple x
- strin
et)
-EX mport numpy a P
ar np. aray ( CL 23+J)
print (car. dtype)
t int 64
as nP
fmport yumpy
EX banana,
chery])
ar = np. aay ( 'ap ple',
print (a. dtype)
ot: UV6
o NumR amy
nctions ohjeca
the dimensims ef
ndm speciA
ndtm araynamt .m dim
Syntay!-
as np
import numpy
EX
p . aray (t L23)
a
print Cahdim)
an array
datatYpe of
ftes the
dtype specf
ttpe
anay_mame. atype.
Sax
numpy
as np
EX mport
(C1.2,,3.J)
a -[Link]
pint (a dtupe)
d flod 64 nxn shape o aa
am
Zirosnfun chm cheates
zeros
(Un
Syntax zeos(n)
a np
ER a import Nmpy
a [Link] (3)
print (a)
ott Co.. o. o.
EX2 import TumPy a nP
a [Link] (, t,3J
print Ca
uts CLo. o. o.]
Co O. o. J
giumbel af
rocos { numbc af
OF
Shape- &tspeé-fy the
Golumn e4 am eray
Syntax araynam e Shape .
import mumpY TP
EX
rray CLC,4,9J,
,,7FJ)
a np.
Print ([Link])
out 3, 4
elemots U
u I nin a
annr
tt cheats the all -the
mes
as nP
EX import nunpy
a np. Ones (L3J)
print Ca)
caange.
arang e -fmctier Aeturs-thc Values -from
end Value.
spectfleef tartiny value -Lo
a mP
import mumpy
np. arange ( 1o, 20, 1)
Printta)
13, 1, 5, 16,
17 1, 19
out Clo 11 1 vaues tn tpetoeer)
Space u e s tn tpetoce
the lnearly
Lrnspace : - t icturns
I
Valurs.
the Speicd
as np
EX import nUmpy
P. nspace. ( 10, 50, 5
Prínt (a)
30. 40. 50J
20.
out 10. Shape. -fre
SpectHcd
the
it Aetur ns
uin eshape
dray
numpy a nP
FX 7 pot
[Link] ( [ 1, 2, 3, 45J)
a-
print (a (2,3))
prfnt (a. heshap
CI23 4 S J
Out
CCI3]
untt matrêp of Spectfi dmenstray
«d
Aetums-he
.
(y) eye t
mpt numpy as nP
EX
a= np- eye (3)
pint (a)
out: [ t . o. o.]
D. l. O.
o. 0. . J
a Taa
rayy specify th
Speafy tha
Lndexing e
- NumPy Arcy mdexing 6
clenment- in an araY
particula
a np
EX emport Tumpy
a np. aray (C Ca,31 [4,5],[,UJ)
print Ca[iJfoJ)
a np
EX tmport numpy
[6,11,T TJJ|
E (2,s],
(+.5])
a n p away
(E
print Ca[6] (i] CD)
Ouf; S
Operaons n ama
amay
Mathemattcal
do - t h
mathematical operattomS
Cam
twe
divisfm on each
Subtra ctm, mu t ipitafëom,
lite acldtim, fSo we Com prdem
elcmunt a e m a y
auo evry
Standard deviuttmm,
re ean,
Hke stati stc operatt
aS NP
FXtmport mum py
ar mp. array CLo, ao, 30, 40, 5 o
print (ar)
print (arr +5)
Pnint (ar-5)
print Camx2)
Print C a / s )
3o 40 50J
o u t (1o
20
34S
25 3
60 o 1007
2 0 uo
G oJ
C4
TUmpy
a np
mport 30, 4 SOJ
P . Cray
( [lo, 20,
=
mean (arr)
nP.
av
("Mean i " ,avy)
pint dian (arr)
= [Link]
midelc
(median " , midele
print
nP. std (arr)
std val s t d _ d e v i a t o m : " ,
std_Val
print (
30
50
pANDAS
featuses of pancas
perfomance. data Amalysis.
1High data s e t
to working wfth large
tisused
2. differontormats
load ftles
wth
t t supports Cor)
3.
A ore flexible
Sents n Tabulas wa
S Repre
data.
en missîng
G.
working
on lage data
indexing -
Slicing st easily
dêHerent
deota
-two
Merge cor)joto
th data set
7. Perhape n prthm
Ustd in
vsd
tohfch ir
tohich
a
a brary,
tbrary,
Panda
Pandas stucetua
ThRec data
with
t deal
s eSe hies
Dataframe
(u1) panel
k c StAu otare
Seie s S a one dimen sional aray
SeAie Can be CAeatrd
Seles can be Cieated
Panda s
data. #
[Link] Valuu
wth
pfct ,or
Dct Scala)L Valun
Scalal
ke -
Aray, iF,
Va^low in put
vsing
vring
Sytax : Pands. Señes Cdata, index, dtype, cop1)
FXO Chcate a Sc&ies -from mdarray
import pands as pd
as np
tmport Mumpy
red')
data =
[Link] ( Blue', whête',
s - pd. Seile s( data, index =[1, 23J
print Cs)
Out Blue
whitc
Yed
3
dfct
EX GAcate a Se Ales-fram
Pandas a Pd
emport
d a t a = f ' a ' 0b':
, e; 27
S Pd. Seri es (data)
PriatC s)
Ott O
tuo- dmensiane array
Dalatrame - Datatram e. is a
data f o r FXample,
wth heterogeneous
NAME AGE GENDER
Pama 2 M
stta
shna 2 M
cAtate d
pandas DadaFrame
can be
oytng
ostng
Various fnputs ikeE
Lists
dict
Se leS
hdanYaS
Another dataframe dttp, Copy
dex, colemn,
[Link] ( data, tn
Smtak
Data frame
rom lvt
GReate_
EX
EX
as pd.
Pancdas
Emport 'Female'J,
]
Male' [ita, 22,
dda-L [Rama 25
4rishna', 2 , MaleJJ columns=
indey - C2, 3J,
Pd-.
Dataframe ( data,
df =
C'Name', 'Age', GenderJ)
print (df)
NAME Ag Gender
out
Ramo 2 Male
Female
sita
Male
krisma 2
D a l a t T a m e - f r o m
dict
C&ecete
pandas
as Pd
tmport age':[2522,
[ Ramae' ta',*rishna'
dla 'Name':
[Link] e(data)
df
Ott Neme
Roaia 2
2
Stta
'tishna 2
-the Datasal inu
: Manipulating
Manspulating theDatasets or br Acmoving
o r bt Äcmoving
adding column
C olumn
addng
can be dent tr
Datatrame
Colum)
SyTtaxfor addtng column
Velue.
.
defail
col_mame
D a t a f T a m e n e t o
EXpress n / Cmdittor
frame'neaCol
mane"J =
Data
Columm
Syntaxfor
Removing
"Colurmn_name")
.drop(Colums =
DAlaframe
"column-name,
inplace =True
columns =
eta-ftam e. arop ( be
low. df
belo).
ddtaframe given
Smsidcra
F 1 Name 5vbl SUb
S0
1 Pama
sit S
3
rishna
be Jtore in
dn d Svbz Can
mark
un subl
Rdditin
Total Colum
au-folouy
Addng Total columm to-he Data-frene .
print Cf)
Out 1 Namet Subl Sub Total
Pama 50 125
sta 60 130
&0 2S
3 ishmeu
dataframe
we Can manipulate the
rom above data-frame,
rom folloI-
asfollo
as
Name" Colum)
by Aemovern9
"Ncume, înplace True)
=
dtdrop (columns
=
print Cdf)
Subl Subz Totel
SO
7013so
33
Fo
1
methd wed
pata set - Descaibe ()
Descibtng
S t r n s t i ca data tte per centile,
percentile,
Some
for calculatfng
numerical Valucs Othe Series or
mean, std ef
ptafame include
Datatrame. desc Rbe (Percentiles Nonc
=
e
None,
Symlay-
encude =None
EX import pandas as pd
as np
tmport umpY
(C1,2,3)
a'= Pd Seies
[Link] t)
Count 3.0
2.0
std 1.0
min 1-0
15
2S
So2
15
max
3.0
dtype flod 64
u swed
cd
gRoup by fumch'nm
p a n d a s ghaup
fumctiom
Ghoup by Jumetton
a
on Cate qortes
Categontes
based
înto giouPS
ghoups
data
-for Spliting the
[Link] ( " columm_name"
Smtax :
data-freune as d
cniider t h e
EE event
1daycty emp wind spce d
Pain
o1/2022 hedarcobmda7
hyderaba d a Sunny
4 /a/2022
2 / 1 / 2 0 23 M u m b a t 30 Suny
3//9022 Mumbai 2 12 Jno
Snow
3
41/302.3| Pone
6 Paî)
b/301/7/20 pont
No we do, 9oupfng by date
'cay')
g df 9houpby (
wind Speed | CVenF
t
clay
6 Patn
hy derabad 27
Sumy
/1/207 Mumbat 30
Sno
pune
Suemy
hykrabad
13/202 12 Jneo
Mumbal
pune 2 Patn
iloc) methods ar
data set o- loc ) F
Altevng the
data nh datasct
datast
hefttering
Ueful to do label bascd cdata.
Label based data
method Ü a
Loc C) tocc)
Setcttng method
Column label
Dataframe. loc LRoco lab l ,
Symtax
d a t a r c m a s
Shown beloo,
df au
Cmstder
Ey
Name Subl Sub Jub3 Jub
Kama
Sita 10 3S 60
2 hma
3Padha 5 37 3 6
Siva 10
data set ifomat lon oS4
GAcatiny neo
"aud Radha
Stta, nisha,
newdata = df. los|1:5,
mc- c t a
out Name Sobl Sub Sob3 Tob
Sta 3 SO
2 Tuhn qo 3J
3 Padha S
38
datu
a ndep: balied
loc.c): {locC) nethod
lecto metho f.
olumn-inder
Datatrome .lloePoo_indes,
Smta:
Smtax;
heatin9
Aeating aa ne
neuo
above df pdto-frame
rom Pacha
onformalTn o sita,rishna,
data S t
df. iloc[14, 0:
cdala set-
data Set
Oud Name Sub ol Nb
stta 3S fo60
3 5S
3 Padha SS 37 3
mfssing Values n dataset - dropnaC),fumat)
on mis sing
missing
methods
methods are Weful to do the. Operatton
Velues.
Uwed o .
)dropna () - drepnal) method
movc
etthe ho oL e s t an
ce. o "mfssing
missing
Value
JYmfaxr [Link] )
ee Shoon below,
shown belo),
a Daabrame
Consi'dcr df
EX
E X
Subl
Sub Sub3 JUb
Name
10
Rema 70
Sfta 6S
6S
arishna
3 Padho 40 60 SO
missing Value
ERemove
= d f . dropnat)
newdata
mew_dafa
Sub SUb3 Sob
NameSobl
O
ama TO
JO
60
3 3 tha 4D
wd to fey 1h
method'
r i l n a ( ) f u nat)
Values
atenate
with
mssng Vakues
missn
Dtatrame. felna(
value)
Stax
fu)
Derfafrome. feuna
method
metho d'- "
bAu)
d- "bAu)
D a t a f r a m c . f i u n a
( metho
Datatframe
the above df
Consfder
method-feu)
=
[Link]
Dtaset
Daa-St
O Sobl Sob- Sub3Jub
Nam
Pama 70
I Set o 65
oio er
ha 6S
3 70 6S
Padha 40
mcthod
Concate heition of patast Cancat ()
o Drtafame).
UsedLo Con etenate Co) adding
Smta mdas. Concat ( [ DataFrarnel, Datatame,
indey = "inore"
as dfl dH2 a
X Cons der uo data-frames
Shown in below
Neme Sub Sob
dl
Reuma S
rUhna 0
Jobl SUb
2 Name
Stta
q0 10
shiva
Cnatenále cHl df ndex
Concat(Ldf1,df2]
=
Pamdas. Emore"
petaSet
D a t aS e
fobl Sob2
Name
Paima
10
rishna
2
stta 95
3 Jhiva
tb is data visualizaton pakage in
Matplotlib - Matplot a
mothing but Shouoing in stghts
sightr
Prthon. Data Vtsualization
Cor) ghaphs.
(or) chartr Co)
pictures
fo data ntheform ol
Those are
. line plot
2 Seatter plot
3. ta-plot
4. tirtoghams
S. pie chart
et the. mo
most
plot s on
Seatter plot - Scater t i sUftd
pac kage
package. .
mat plot l&b
in -the of
populasplot
data potnts
data
Aelatton betweenn
betuoee
shoethe dependent
too
olfpt
ofpt-coO
and
ictble
varichle
Var
independeit
inpat (ov)
tnpat oo Data vualzatlon plot
in -the
Variable plot. Scattir(independentvar, dependent_Var,
Prplot. Seat
Syntax 9mark
Color
as
as TLp
Tp
Tumpy
EX
import
import pYplot
au pt
matplotb
x nP. aTay (C 10,20, 3, +0
200])
yY
nP. arTay ([ so 100 So, color-")
Sçatter (x, Y, marts -"+
pt.
inprtx ")
"
pt. Xtabel (
y")
pit Ylabe (outpet
S c a t t e r plot")
tttle C
plt.
plt. Shoo
Scatter plot
200
00
50
20
0
enptx