In[33)) import pandas as pd
‘Empty Data Series crested
= pd-series)
rina)
Series), dtype:float64)
CAUsers\Welcome\\AppData\Local\ Temp\ipykernel_16720\1694814139 py'5: FutureWorning: The default dtype for empty
‘Series wll be ‘object’ instead of ‘float64” ina future version. Specify @ type explicitly Yo silence this warning
‘= pdSeries()
n[31} import pandas as pd
import numpy asp
‘#Data can be multipled by list form only
FetoybifedJe'F]
iC Eien, “aralie',Bommie')
Series(deta= O°2, index = F)
Sindexsname = ‘The Vanpire Diaries
primes).
prinv(Sindex)
‘The Vampire Diaries
a” Elena
Caroline
© Bonnie
d Elena
© Caroline
Bonnie
ctype: object
Index(('a','b'
"FJ. dtypes'object’, name="The Vampire Diaries’)
Tn[22) import pandas as pd
Import rumpy os np
‘#Any data Series can be given name by ‘index name function
= [ Hom’, ‘Dhan "Nilo, Pravin’
S=paSeries(L)
Sindexname = 'My for
pines)
My family
0 Hanny
1 Dhani
2 Nilam
3 Pravin
type: object
In[I7}. import pandas as pd
import numpy a: ip
#We can slice aut info from range function by default index number
F = {'Phoebe', ‘Monica’, ‘Rechel' Ross’, ‘Chandler’, Joey']
S = pd.Series(data = F)
Siindexname = "FR. T.E.N.D.5."
prints)
prim(St03)
FRIENDS.
Phoebe
1 Monica
2 Rachel
3 Ross
4 Chandler
5 Joey
type: object
FRIENDS.
0 Phoebe
1 Monica
2 Rachel
ype: objectIn(27}
In (30)
Ins}
Import pandas os pd
Import numpy os np
# we can give index and data by our choice , nat default numbers
names = CPoyel, “Sujata
age = [45.27.35]
info = pd Series(index = names, dot
prinv(info)
‘Tayo")
‘This cn be used to assign index to respective data series
‘Hand create data zeres directly by [] form
A= pa Series((44,57, 62,74, 89))
Aindex=('a',"b' 73 'e)
prima)
‘Hata Series can include string, integer, flaat and none function all at one time
‘#Index can be assign by range function
V= pd Series((’Ram", npNaN, 10, 20.7) index = range(4, 8)
print(V)
Payal 45,
Sujeta 27
Joya 35
cdtype: into
244
b 57
© 8
d 74
2 89
ctype: into
4 Rom
5 NaN
6
7 207
type: object
import pandas 0 pd
Hata Series can be also formed by dictionery
‘Hata type can be decided
data = ("Thyme" : 70000, "MI" : 45000, Ren”: 65000, "Kavin® 68000)
F4 = pdSeriestdate, dype = 'float32")
Faiindexname = F4 Thlond*
prin(ra)
print Length
fen(F4))
4 Thailand
‘Thyme 700000
MI 450000
Ren 650000
Kavin 680000
ype: float32
Length : 4
Import pandas as pd
‘string in ist() ore printed separately in form of each letter
L= pd SeriestisnLucifer")
print)
ype: objectTn[26) import pandas as pa
Import numpy as np
‘#orange function in np give data series with default index number and data starting from 2 to 22 with 3 as difference betwee
X = mparenge(2, 22. 3)
Y= paseriestx)
print”)
orange function includes float
parange(2, 16.1, 3.5)
K= pa Series(Q)
print(k)
Halse includes subtraction(24 to 6 with difference of 3.5]
“
7
20
dtype:int32
2.0
55
2 90
3125
4 160
type: float64
o240
1 205
2 179
3135
4 100
5 65
type: floate4
°
1
2
31
4
5
6
In 22) import pandes as pd
import mampy 0 mp
Horonge function in np can als be used to form list
In(33}
Hlinspace function works...Check in Textbook
P= npulinspacel2, 12, 6)
Q=pdSeries(P)
print(Q)
0 20
1 49
2 60
3 80
4 100
5 120
type: float64In(37}
In}
Import pandas os pd
Import numpy os mp
‘tile function in nunpy gives the word 4 times as mentioned
S = pdSeriestn,te("Ram*,4))
prints)
‘tile function with list form gives each etter repeated 2 times as mentioned
= pd Seriesinp. tilelist(Ran’),2))
print(5)
0 Rom
1 Ram
2 Rom
3. Rom
‘type: object
z
°
1
2
3
4
5
ae rae
type: object
Import pandas as pd
‘range can be used for index. Here itis from 1 to 12 leaving difference of 3 in between
#100 written in data will be printed forall indexes
V = pa Series(i00, index = range, 14, 3))
print)
‘string can algo be used as indexes but in ist form
V = pa. Series(33.3, index = (Nina, ‘Zan’, au!)
prin)
‘Hbifferent numbers as data and different strings as index can be used by list form
W= pd Series({15, 65, 20], index = ['Shanaya’, ‘Abhimanyu’, ‘Rohan’ J)
print(W)
Hlst() form can be used so that written string is printed each letter separated
X = pd.Series(ronge( 19,3). index = ist (‘TIGER'))
print)
#other then list() form, we can also used [x for x in") form
Y = pa-Series(range( 15, 4), index = [x for x in"LION"])
print)
1 100
4 100
7 100
10 100
13 100
cdtype: into
Nina 33.3,
Ten 333
Paul 33:3,
type: float64
‘Shanaya 15
‘Abhimanyu 65,
Rohan 20.
type: int
Tt
4
67
E10
RB
drype: into
wt
r5
08
NB
type: intoTn [11} import pandas as pd
Import rumpy os np
‘np Nan function from numpy can be used for no value. And when used, other integers are written in float form
K = pd.Series({90, 100, npNaN, 200, shiv")
peintte)
2 90
1 100
2 Now
3 200
4 Shiv
ddype: object
In[17} import pandas as pd
‘#uhen list is multiplied, values are repeated by repective number
And when data series is multiplied, vlues are multiplied by repective number
list
6, 8,9,12) #
print(A* 2)
type: into
In[21}- import pandas as pd
import numpy 0s mp
‘this can be used for multiplied value of index or data written i lst form)
r
12,5,9, 11,15]
P = pd series
print)
De 2, index = 1)
‘#function’**" is used for exponent(power of given number)
C= pa-series(data =
print)
24
5 10
9 18
M2
15 30
type: int32
20° 400,
45 2025
70 49.00
95 9025
type: fleat64In(34}
In(33}
import pandas s pt
import numpy os mp
Trd= mparange(®, 21,3)
d= ['Sie’, Rayna’, mpNaN, “Tes
P = pd Series(dote = 6 index
name = “ABC
Piindex.name = ‘mocks
print)
print(index)
Print(®volues)
Print dtype)
print( shape)
Print(®nbytes) number of rons 8
print(P.ndim)
Print size)
Frint(Pstemsize) not to be used or asked as per syllabus
print Pempry)
print( P.hasnans)
marks
8 Silas
ML Rayna
14 | NoN
17 Tessa
20. Sybil
Name: ABC, dtype: object
Inté4Index((8, 11, 14, 17, 20), dtypes'int64' names "marks')
['Siles" ‘Reyna’ non "Tessa! Sybil]
object
©)
1
5
False
True
import pandas as pa
import rum os mp
A= (7, 40,61, 80,97, np NON]
3d Series(A)
Bingexname = "ABC*
prints)
Print(Brname) ff no rome is essigned, output is none
pont(.index)
prinB values)
prinv(®.drype)
Print(® shape)
Print(Bnbytes) number of rows «8
prine(Bndim)
[email protected])
prinr(Bhesnans)
print(Bempry)
aac
0 170
1 400
2 610
3 800
4970
5 NaN
ype: floaté4
None
RengeIndex(start=0, stop-6, step
17,40, 61, 80, 97. nan
floats
)
48
1
6
True
FalseTn[36}
In138}
In(47}
Import pandas os pd
Import rumpy 0s np
80, 70, 60, 40, 33, 75)
100, 23, 44,56, 70, 10}
Z = pd Series(Y, index =, dtype = "short")
Zindexcnome = "ABC*
Zrame = "SVHS"
print(Z)
rint(Z.nbytes) #When short is used as dtype, number of rows is multiplied by 2
aac
80 200
70 23
60 44
40 56
33°70
75 10
Nome: 6VHS, dtype: intt6
w
Inport pans 5p.
Brame = "Rll number"
print)
peinn(Bl'b'D
if index i twice, then output wll be both the values
‘it youwant values of more than ane index ct once, then are tobe used
1 The output willbe according the the sequence asked to print
‘And all values of each index wll be printed
print(BUb','e' ‘aI
25
23
44
56
70
10
Nome: Roll number, dtype:int64
Nome: Rell number, dtype:int6
Nome: Rell number, dtype: into
Import pandas as pd
import rumpy 2s np
parange(O, 34, 2)
rh Series(A)
printVILI2, 7,2, 10]) # indexes in) wil be printed from choosen data series
ararge(0, 8,2)
1d Series(S)
print(G[1: 9:1) # date can also be choosen by toking indexes in range
1 24
7 14
24
10 20
type: int 32
12
24
36
type: int 32In(50}
In(2}
Import pandas os pd
Import numpy os mp
P= V{0: 9: 2] #° here is range whose value will be output from data series V by its index
print)
z
%
20
type: int32
32
ctype: int32
oo
28
46
type: int32
Import pandas as pd
import numpy 0s mp
A nparange(5, 20,2)
V= pd. series(a)
print(V)
After updation
by assigning the index numer whase data isto be chenged
VI0-7: = 'NNN # by giving range of index whase dota sto be chonged
‘Both ofthese method canbe used for replacing data
print)
05
17
29
3
4B
5
6
7
4
°
1
2
3
43
5 mr
6
7
19
ddype: objectIn(66}
In(67}
Import pandas os pd
Import rumpy os np
HEAD and TAIL factor
A= mparange(5, 25,2)
V= pa-Series(A)
print)
prinr(Vhead(7))
print(V ik?)
3
type: int 32
import pandes as pd
import numpy 2s mp
ins 1,5,3,6,2)
4A = (20, 30, 40,50, 60]
‘A= pd Series(data = dA, index = iA)
print(-Data Series A is")
prin)
Bet, 2,3,4.5]
a8 = (200, 360, 400, 500, 600)
B = pa.Series(data = d®, index = i8)
print(Data Series 8 is")
prin(@).
Cr A-8
print(-Data Series Cis")
print)
Data Series Ais
120
5 30
type: into
Data Series Cis:
2200
3600
4400
NaN
6300
‘NaN
ype: float64In(67) import pandas as pd
Import rumpy os mp
print(V)
rint(ViV>65),
‘#for specific intervalic value, we can used (dataname[dataname ‘«‘or >" or '=' number])
OP = [38, 30, 7,18, 0,55]
QR = pa. Series(OP)
print(QR)
Print(QRI(QR>30) & (QRe=90)) # using "relational operators
0 35
50
78
89
o
55
type: into
278
389
4 67
type: into
038
1 30
27
318
4 90
5
d
55
itype: ints
ose
27
a 50
5 55
ype: inte
In {69} import pands as pd
import numpy 25 mp
V=pdseries(ay
print(V)
print(VIV=="a') # for single value
Print(V[(V=="a') | (V=='p')D) # for muttiple values
Houtput willbe as per sequence of data series not assigned value
°
1
2
3
4
5
6
7
8
9
d
o
5
d
nn
°
P
P
ype: object
pes object
1p
5a
6 Pp
type
ype: objectIn{7O} import pandas as pd
Import rumpy os np
print(V)
Q= V.sort_values(escending = False)
print(Q)
P= Visort_values(escendln
print(P)
‘True) #output will be printed with respective index number
°
1
2
3
4
5
6
7
8
9
4
9
ype: int
20
ines
Beevoanadewaaveort
7
8
5
4
2
1
°
6
3
4
3
6
°
1
2
4
5
8
7
8
9 20
ype: it
In[74}: ## Reverse the oll elements in Series
import pandes a pd
import numpy as mp
UP [90, 100,80, 0, 70}
A= paSeries(.)
print(a)
Ureverse()
8 po.Series(L)
print)
© 90
1 100
2 80
3 50
& 70
ype: inte
or
i 50
2 60
3 100
4 90
type: intoTrUs}
In(75}
Import pandas os pd
#for changing index
‘A = pa.Series(data = dA, index = iA)
print(‘Data Series A is)
print
wr TV, V4]
8
printData Series Ais"
pine)
for rearrangement of data as per index
indA = (0! 'b''p',"9'F]
data = [22, 33,44, 55,66)
P= pd SerieS(deta = daa. index = iA)
print(Dota Series Pi
print).
inc
@
print(Dota Series Q is")
print(Q)
Data Series Ais
2 20
b 30
type: into
Data Series Ais
I 2
i 30
mr 40
WV 50
v6
ctype: into
Data Series P is:
a 2
b 33
Pp a4
955
F 66
type: into
Data Series Q is:
p 4a
455
7 66
2 22
b 33
type: into
Import pandas as pd
‘#for dropping or removing particular data by index
prinf(-Data Series Ais")
prin(a)
ropt'9')
prin(A)
Data Series Ais:
a 20
b 30
p 40
2 50
60
drype: into
a 20
b 30
9 50
60
type: into