unit-V python (4)
unit-V python (4)
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
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.
out 10 20 30 OJ
pnt Cdrrl drtppe
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= np.array
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
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
t int 64
as nP
fmport yumpy
EX banana,
chery])
ar = np. aay ( 'ap ple',
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 -nP.array
pint (a dtupe)
d flod 64 nxn shape o aa
am
a np
ER a import Nmpy
a np.Zeros (3)
print (a)
ott Co.. o. o.
a Mp.zeros (, 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
import mumpY TP
EX
rray CLC,4,9J,
,,7FJ)
a np.
Print (a.shape)
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
dray
numpy a nP
FX 7 pot
mp.aray ( [ 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
EX tmport numpy
[6,11,T TJJ|
E (2,s],
(+.5])
a n p away
(E
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)
= np.me
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
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
data f o r FXample,
wth heterogeneous
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,
pandas.Dataframe ( 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=
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':
Pd.Datafam 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
a.descAibe 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
PartaFrame.ghoupby ( " columm_name"
Smtax :
data-freune as d
cniider t h e
EE event
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,
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 Dalatrame.dropma )
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
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
the above df
Consfder
method-feu)
=
df.ftuna
Dtaset
Daa-St
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
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
=
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
3. ta-plot
4. tirtoghams
S. pie chart
et the. mo
most
plot s on
Seatter plot - Scater t i sUftd
pac kage
package. .
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
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