You are on page 1of 18

Cle ax method

mehod cou cleay the ente ist but the lish coiti be availo
Ihis

X. cleax ()
Piat (x)

Pld i'st items exBend


Concept these ane 3methods insest, apend,
In this
melkod
an item at the end of ist coe
pend mcthocl - b add
Can ose tbi6 method

f'aongo', Pogja',
X. append (inana)
Paint (x
item at the specitied index
setan
Insert methad - To in

('dongd', 'Pooja', 'so6)


Xe io eot (o. 'Hinanca')
Psint (x)

[inane', duga','egja', '3ob J


want to add the and kist elemeots
&rerd eHhod ’ D you method.
to the 1s se Can UsethIs

X l'yinonca','hyd','Pgdn'J

Xoextend (y)
Paint ()
Chiance', 'hyt,'Pgdm','b
foa loop using i'st
list
Cceate a vatioble coith 3elements by osing
x- 'choco', 'bikki','ve'
j6 yin x:
Pst in t Cy)
choco
bilck?
veg item.
to point the inder numbe using
Bample pageam
Method is Pndex
X ['ehoco' Scocet,' veg'
=

x. fodex ('veg')

OKAmple prglam on &ft method.


X = 'ehoco' ,'chixki,'bizki'J

Pstnt Cx)
object of type set may be Created by enclosing elemerts .
Set bet oithin loops ot 1
Notc: The elements c a set & ace seyuiaed to be îmmutable
Objects.
Set concept doesnot Soppt Podexing, sihg, add moltiplta"
operata.
.
Sels ae OnGdexed go that the user Cannot be Sse n coh
the elements ae auailable in the outpot.

Erample pxogtom Onon Sets


X"itbm.
<foj"s-b
Psint (x)

=icbm', la, "sbe'


Point (a)

Unchangeablej Set has beeo ceated


t cannot change the itemS once the
Ekample pxokam on Get Osing Consfucto
V= et (aeiou')
Potnt Cv)

Exaynple pxogam on set by using sting ,ineger, decinal &


boolean
Noe: Bolecn means ToF

k- fia, 4. 8,'s, Tue'


Psin (t)
$9.s,'s, i2, Tsue ?
& xample poogfa to get the output as< class set >
X- 'icbm, 12, 3-6f
Psint (x)
Poiot (type ()
{3-6,'icbo',ia
<class 'set >

Q Example pxogiam on set osing Condl tfon.


2- o, a0,30
Means

Pslt ('io s auailable') dynamie


hQveto
take
Coe
else:
Psint ('io is not available')
10 ls available.
0sing length method
Evompe poxogam On Set
z -f1o, a0,30
Piot Cleo C2)
3 in set
to add elements
8 Exaple pocogaam
a{'Ram', 'sito', udy 3
a.add(' koish)
Psint (a)
?
kaish','Ram','sta','ucky
& Remoue Method
-$'Ram', 'sita', 'ucry 3
a. enove ('Ram)
Pstint (a)
sita ,
clece octhod

a-'sita', Ram'
0. clean()
PsintCa)
Set ()

Discand method ombex s fomthe


Speiied clements Same aitenia, but
The cíS(uxd senoues
method also the
Set coheveas stemove
Set emove mettod oil
auafabe fo he
the Specfied tem not
method colnc aise an
s discad
ushese
Stalse an eors.

&={' sita','Ram
a.discaxd (' Rons ucky')
Pstint (a)
$'sta', 'Rarm'?
ONIT3

Vsual'
wm yalion
V&ualieat t is a a dionersional gaphftal objecB
including
etc.
Ine, ciscle ,Teclange methods thal
pxovides seve xal
Iython bsax y mat plokp speciie
dacilitate dawing the otjects to be móe
barchast etc.
This libxabr9 Soppit hislogiam
How to ostatl matplolib
PiP instatl matplotib

ctol+ eoter
paint 3,a
& Example progzam on v>sualization to Matplctli
keycooid called
Note : Pox uigual2at
cue have to assigu a
have to

Pmpot matplo tib. Pyplat as plt


n B]:
Ptplot (3,a,'vo')
PIt. Shoo()
draco a shgle point 3,@ on the giaph
Note: Suppose c0e cosh to takes a axquments
use plot
fox this cwe can 0se
tunction that
coodinates so that the shoco funckon is Used to display
as
f the usex Cuants t Ied cisce di a coloit
the vlealizat?
can depresent O» phabet Do the above exampk
Pont Coe
epsesented coith x0'-'Y' Ijers to sedciscke o
co thth Some otheY
aepoesenls the ciscles Coe can assign ai
etc
Colors ike blue, qteen
&xangle paogam to plot 5 poinls onOn x-yais by sing Halplou
h (o): ngostmatliotlib fyplct as plt
x- (2,3,5,1,9)
y- (,4,6, 8,10]
Pt-Plot (x,y, 'go')
PlA. Shoco()
Nok # coe cont a solid loe oith colQ these ane
and cdo.
options Jo line,style
Solidline de<ault
dashed line
dotted lioe
dashed &dotted llne
outpt
pot as solidl loe coith cd
Example paogtam to get oUt

impoit matpctlib.flyplot as plt

Pt plot (x, v,' b-')


tine
Plt.shoco() b to get * in folid
need Cue an
USe after
we
SIze E,
Iioe codlth.
inCoease mmatkes aa
Exomple pxoglam to
[R,3,5,,4jPotas
(mpost matbtib. plt

y - ( u) 6, 8,i0] lnecoidtb >5)


PlotCx. y,'*.} ) masker size - l0-5,
PE.
Plt. shool)
chat
to add Htle to
Buample progzam
chavet
Note TÌ He jonct" co paovide the title to
Plt-ttle ('s-b)
PlE.Showl)
the user cwant to assian the title coith dij! doot size &calo.
coe can Use the patamehers like font Si2e E, Cold .

X= (a, 3, 5,7,4)
Y= (,4,6, 8,10)
plt-Plot (%, y, 'a- maskeb Size -10-5,linecoiath : 5)
PlE. title ('s-B', Jowtsize =30, coloi 'qoeen')
PIt. showc)

* T) the user coant to a ssigu xeyaris on chant - lable funct


wMassiqn he x y axls lahel o chat.
impt matplotlib. Pyplbt as plt
X= à,3, S, 1,4)
lo.5, lioe colelth -5)
y*--) MatkersiZe =
PIt" PlOt (X) y,
'qpeeo')
Plt.ttle ('sB' ont sze - 30,coß -
Plt- xlabel ('x-axis')
Pt ylabel ('y-axis')
Plt. ShooC ) chaxt
to oe oreate a bx
bromple pxogtam to
9e lib-Pyplot as Pt
fmpos & matplot ,sipso']
Companies = [L&T' 'inlosys'
Values = (aooo, 35000, 190oo)
Plt. bas (companies, ualoes, col Û: lgeen
vales')
plt.titte (Maaket
values')
Plt .leqend('Masket
Plt. ShocoC)
Nomesical hckaqe fo Ratho
Nmpy
Ihe entie conept o the Jon q aays to edtact tbe u
om fand
as pes ndex (oitesia. his slcudd be vaed in the as
dinensional
seseaxch to exttact the 0OS E Columns fn A
packagc bsan
Note f& thfs Cue have to nsta nomeial
called Normpy
Hauwto Pnstall Nompy
Prp nstall NUmpy
Reautse ment alseods satisled : nopy in c:luses] i95
an aconda 3\ lib\site- PacKages(1. 24.3)
|Brample poogam to point any 5 ombers using nompy
imeot ompy as np
da =np. axsag (Cha,3, 4,5])
Pint (ao)
,a, 3, 4,5J
Exomple paogfam oo ze0 dimensfonal aoay
Impost ompy as np

Paint (ar )
5)
Exomple proq3am to point &dimensional array
impost mpy as np

sPace spoce

Exa mple progeom to extact the 3d e lement dom y


fmpost numpy as nP
as 3 np. Cay( [ a ,3, 4, 5))
paint (as 23)
3
Example Pioqoam to coeate an aoay catth 5rmernbevsextact the
and &3rd elenent and add them.
impost mpy as op
as = np. asTay( i, aa, 3, 4I,59])
Point (ass ]+ ax [2])

Example pIogRamto paint ubers by Using amange fonction


impost numpy as np
as= op. amange(s0)
Point (ar)
diude I num bexs nto 4 oOS & 3olomns
to
Examele Poqsam
OSing seshape tunctfon.
impost ompy as np
ass = np. asaylco, ,a ,3, u, S, 6,1, 8, 9,lo, ) , 3eshape (u,3)
pint a)
[co 22
(3 45]

paoam to point 50 nombers and assign int lo


Example
XOcOS and 5 olomns

impost numpy as np
(io,5)
as np. asay(50). reshape
Pint CaY)

(5,6,7,8,
Colu mns
To dind out the rowS &colo we can O5e the Shape
cws Columns of
tonchiou so that it psovides the s00s a

Paoticulas Set ol numbex6.


a columns
b point 50 numbers with 53ecoßd:5x00s,
impoit nompy as np
-np.axanqe (So).Steshape (5,5, a)
Psint (a)
Example Progiam on a demens ional anay to extact the
elements Using ompy
mpost nompy as np
dx =np. amaylCCva, 3],46], ,8,9]J)
90 1 22
10 (2 2
patnt (ar [2,3)

pogBam on ibteschanging xo0s § coloms


Exomple
into columns &
e have to wse tanspose to
Colomns into do06
thatb c0e have tD USe
fof

Example Progeam to Toin a aays


impoot numpy as nP
al np. aray(Cia3))
a2 :np.abvay(Cui s, 6)
a3 = np. cacaBena te ( Cal, aa)
*Printa3)
a,3. u,5, 6]
ABndas ba data liosavy to analyze the dato Jom extenal giles
TSV and also data scsaping drom 4bas
ike xlx6 , .csv, "19yTab seperated value
eb pages
.fandas oil analyze Manualy loading daia di loaded
data
Nert Geries object
Data jrame object
"Bast opesations on seses and data rames
Ses ies :
Tt isa
Sesies fs one dimensional gimlar to but in python list
doame.
data tupe that xepxesents each columo the data the
oncept eYcept each element must be
Seses fs similas to list
Same data type.
Note senes dato rames asce Qdata types ß andas so -tbat
the data to identily the no. o cobmns and qso
anadyae dala.
to extfact Single colu mos Shgle xoo
CqUJement.
L9e Can visualize data by using pandas as pey
visualfzation.
9e caro USe rmatploib on pards
Houo to ostall Pandas
!PIp nstall pandas
and we have to eXeCue the Same

Exaple psoqia mto cieate a Sesies


Pnpoxt Pars aS as pd
Seoes(o,'icnd)
s-Pd. ato ])
Paint (s)

dtype: object
Example Paogam to ceate index vaes to Ses'es
fopot andas as pd
S RA.Sesies ([iol,'icbm'), frdex- ('olege. coce', olege . ram
Paint (s)

College.code
name icbm
college
dtype : objet
rome.
ELomple pogYam to to coeatea data
Sid Soame
lo Smith
loa king
assigo lbops ? to getthe
Th this concept coe have to 7
means

data yra me
loops ade dicion ay Concept ans cusly boac keBs

Tmpot pandas as Pd
k=Pa- Datafame({'sid': o,l02J, 'sname: ['snith,'king'13)
Paint (k)
Sid Soame
(ol Smith
l02 King

to reate Subject ad no. ho ws to get


&ample paogtam
the outPot as
Sobject no. o hoo1S
32
Ba
Ba -1 35
38
Ba-Python
Wbite an example pOgam to get outpt as follo0s
Day Fast Hour Subject
Schiect
Monclay H-I
Bo-Rhon
Tuesday H-4 Bo- Rihon

adesday H-3
fPr
Thovsday H
PPr
H-5
Friday H-$
satuYday
e

ay": ('Hon' ue','aed, a,'sat' 'Faist_Heur:


" data
H-i, 4-,it,4-i, '-,'4-], 'sobjict':('Ba-Rthoo,'Ba gliv
Ba-Python', 'eer, FPt','rJ
Datasame(data, index =['Hon'ue', 'wed', 'ho', , a])
"d= Pa.
fame

Poirt (df)
ollowing output cath 4sS
Example pongiam to paint the
Zoluns
C-Name high lo
88

85

9ipro 64

impot pandas as t. [ss,22,64],'oo:f


data -¢c-name': (rgt', 'info', cipo', Hgh':
48,85,713
(data)
df = Pd.Dota Fsame
Point (df)
extact the Index 1 Jhta
Erample pxoglam to
Pscint (df.loc (1])
C-Nanme ino
Hgh
loco 85
Name: 1 ,dtype :object.
methad coi exteact the paxtc ulax Citesia as pes de
>loc
ent.

coeate data fame tabte oth oco fa


Eromple pagam
tebte label.
to
Place
Occupation Pasitiou
St. Scientst Hyd
cientis
4.
SY. Daka Aralgs
Analgat
index - ('Hansie', hiam)
df=Pd. Dakafame(data,
Psint (df) 3OCUlabel iodex
xample posogam to exttact any O
Pyint (at.loc ['Adam"J)
Occupabok thalyst
Positioh
Sy.oalyst

place kyd

Name: Pdam, dype:ojecl


hale
coant to exttact the Conteoi torn inder ue
Noyou method ó ley
Use Roder

Pint (di. inde)


hdoHansle','ndam ], dtype 'object)
Fample poogfam to dind out the mean, so, mar Grn
bint (ges.meonC))
Pant (ages. maxc))
Point (ages- minco)
Point (ages.sdC))
How to fpat dataset.CAm.csv) Comma, 5eperatedvabe

st method
Impost pandas as Pd
/Desktoplgm.csv')
gm= Rd- zcad _csv('e' :usevs/91113/onc Doive
psirt (qrs)
and methocd
impót pandas as Pd
qm=Pdsend -Csv ('gcsv)

ok home page clcH on opload butou.


Kame
In Topyey
Rettive the ile fom yar system &clek on opload.
coiM obseve the Same ile.
NOcU in the Sae page you coil
NOw n neo dile you can acess the Complek data by osingpanda
Sst ue vows dom dotaset.
Ezample psoglam to ettact the
tuncton coilt give the s ive vows feom dataset
Nole: Head
Pslnt (gm. head()) Yocas Jeom datase t
the last dive
Example pxogtam tb extfact rowsJDonm dataset.
psouide the hst 5
Note: Tailontion oit
Psint(qn. tait(1) class pandas
the oufput as
Ezample pxogfom to gt attibutes.
Note! Tpe unc!" wilpoDUicle 4he class

Psivt (typegm))
<Class'Pandas. oe. fame. Datasame
tiampe poiar to gel tolal number o 9o6 ccurns o
hta set.
osco
keyoofd
coiu pHovicde the no-of ows Cokuni
Note: Shap
Jow data set.
Pxtat(qm. Shape
at
(lo6 7, 6) z Columns

qet the cokumo names by using parda


to qet
Favie poogeaKeyoód olumo names b
columns colu proude the
Note :
Csing nder.
Pint lgm.coluons)
'hje ep', 'rop'",
c înde ([ tourtey' 'coaiee', yeas, 'ie ghetap,
od
dtpe-'oet )
type eack Columo
Fxample progtomto get the data data type o each Colur
prouide the
Note: dtypes Heqcooud cl
fit (gm.dyp
Cournty object
Conknent oyet
Yean intc
tieep
Pop Joatcy
Hloat 64
dtyge :oijet
frarnple pxogtarn to the ingoma" about datht
enties the
Nole : inp method oi
data
Polint (g- ino ())
Exomple greproqam to extact Courty colurm by using Subset.
method

County- gm-gm['eoontoy
Rint (County-gm. head( )
Pbint (oonty-g, total County column coil ome
Exaonple pxogBam b extact the coumns, Coonty, Continert

Sobsct-qm [ (Coontty' 'coutinant', 'yea']


Poc int (subset headco)
Example poglamto exttact any sou &s
T] you coavt to extlact a pascticulax xoo febn data
Note: inder.
uSBing
set coe have to use oc methad by

Potink(gn-lc (4})
extact multkple vocas rom dataset.
Exape protam to
Pint(m io [[o,a4,n])

You might also like