Assignment: SERIES
Informatica Practices
of all subjects by 10.
Questions. Solutions
Qu- | Given the following Series
A 1100
B_ | 200
Cc [300
D__ [400
E1500 ouTPUT
Write the command to create above Series and ||3 309
then double the value in series and store in e300
another series named Series? pb 400
z 500
idtype: int6e
» 200
B 400
e600
D800,
= 1000
deype: inte
a. A series object is size mutable.
b. A Dataframe object is value mutable
Q3-_| Consider a given Series , Series!:
200 700
201 700
202 «700 QUTPUT
203 700 200700
204 700 201 700
Write a program in Python Pandas tocreatethe | 303 00,
series and display it. 204 700
type: intse
‘QA _| Consider the following Series object, s
iP 95
Physics 89
Chemistry 92
Math 95
i, Write the Python syntax which will display
only IP. ANSWER:
ii. Write the Python syntax to increase marks _| i) series_object.index[index number]
ii) series_object=series_object+10
OUTPUT: =|
1P 9s
Physics 09,
Chemistry 92
Math 95
dtype: inte4
Fy
1p 105
Physics 98
Chemistry 102
Math 105
dtype: intedConsider a given series : SQTR
QTRI__ [50000
Lgrr2 | 65890
QTR3__| 56780
QTR4 | 89000
grrs__[ 77900 OUTPUT:
Write a program in Python Pandas to create and | O82 9000
apy ees oe
Gina 99000
qs 77900
type: int6e
Q& | What will be the output produced by the Tatemete
following programming statements | & 2? oO Fal
import pandas as pd eu eee
S\=pd Series(data=[31,41,51]) deype: boot
print(S1>40) ->Statement! ‘Statement
prin(SI{S1>40}) _ ~->Statement2 ane
type: intéd
Q.7-_| Given two series S1 and S2
si 92
A 39 A 10
B 4) B 10
c 4 D 10
D 44 F 10
Find the output for following python pandas
statements? OUTPUT:
a. Sif: 2]*100
b. S1*S2
ce. Sfss-l}*i0
Q8-_| Given the following Series SI and S2:
st sz
A 0 A §
B 2 B 4
c w Cc 6
dD 4 OD 8&
series $1 and S2
Write the command to find the multiplication of | §°
B80
e180
D320
type: inté4
Q9- | Consider a given Series , Subject:
ENGLISH. 75
HIND 78
MATHS, 82.
‘SCIENCE, 86,
series
‘Write a program in Python Pandas to create thisOUTPUT:
ENGLISH 75
INDI 18
MATHS a2
SCIENCE 86
dtype: int6@
@.10- | Consider the following Series object, “company”
and its profit in Crores
TCS 350
Reliance 200
Lar 800 print(com
Wipro 150 ompany.nam:
i. Write the command which will display the
name of the company having profit>250.
fi. Write the command to name the series as OUTPUT:
Profit. Tes 350
L&T 800
dtype: inté4
res 350
Reliance 200
Let 800
Wipro 150
Name: Profit, dtype: inté4
Q.ll- | Consider two objects a and b.
2 is a list whereas b is a Series. Both have values
10,20,25,50.
‘What will be the output of the following two
statements considering that the above objects
have been created already
a. print(a*2) ° b. print(b*2) ouTPUuT:
Justify your answer. Option a) will produce
[10, 20, 25, 50, 10, 20, 25, 50)
Option b) will produce
$ 8
2 50
3 100
deype: inet
Justification:
In Option a)
In Option b)
@.2- | Given a Pandas series called Sample, the ‘Conrestanier
‘command which will display the last 3 rows print (Sampléytail(3))
is.
a. print (Sample.tail (3))
b. print (Sample.Tail(3))
c. print (Sample. tails (3)
d. print (Sample. Tails (3))13- | What will be the output of the following |
code? oe
import pandas as pd
s = pd.Series(6,index=range| |
print(s) 920.5)
Qi | Ifseries s1 a having following data,
31
53
% 5 1 6 |
. 4 3 21
n 8 5 3
B 7 7 5 |
4 9 4 |
vy 6 a8
wy 7 i 7
dtype: intes is 4
What would be the result of the command | 37 $ |
¥ 1
print(s4[3:6)? dtype: int64
OUTPUT: |
7 5
9 4
n 8
type: inted
OIE | What willbe the output of the following | OUTPUT:
code? o 10
import pandas as pd 2 ise
s = pd Series(np.range(10,50,10)) 3 40
print(s) deypet ante
print (s.ndim) 1)
print(s.shape) ‘
print(len(s))
Q.6- | Consider the following Series ‘s-
0 40 i 88
1 5.0 Xe
2 70 i 3
3 NaN deg! donee
4 10 or sfo
5 10.0 p88
dtype: floaté4 2
() Write a Python code to add 1 to all the ss
elements. pr sion
(i) Write a code to replace all NaN with 0. a Se
ire
Pater)
deype! Aloneee
G7 | Predict the output of the following code. OUTPUT:
import pandas as pd we
import numpy as np fas 0
data = one’’a' 'two'"'b,three’“'c} dtype: object
s=pd.Series(data) a
print(s)
print(s.size)ig python
sequence [2,4,6,8] and default indies
OUTPUT:
o 2
1 4
2 6
38
dtype: inted
Qi9- | Write the output ofthe following code fragment. | OUTPUT:
import pandas as pd ° i
s2=pd Series({'i","am", "a","student”)) a -
print(s2) 3 seudent
dtype: object
Q.20- | Write the output of the following code fragment. OUTPUT:
import pandas as pd 2 200
s1=pd Series(200,index=range(2,13,2)) $ ite
print(s1) fo 00
i2 doe
atype: ints
Qi- | Write the output ofthe following code fragment.
import pandas as pd
slapd Series(range(2,11,2), index=[x for x in
abcde")
print(s!)
Qa2- | Write the output of the following code fragment.
import pandas as pd
s3epd Series(index= range(10,15), data=x*2)
st=pd.Series(x**2,x)
print(s3)
print(s4)
Q.23- | Sequences section and con
‘bution store the
section name ('A'B',C''D',E) and contribution
(8900,8700,7800,6500,nil) for charity. Your
school has decided to donate more contribution
by each section, so donation has been doubled.
Write code to create series object that stores the
contribution amount as the values and section
name as indexes with data type as float32.Donation by
n 6300.0
B 8700.0
7800.0
D
E
B 1740.0
c 15600.0
> 130000
(Q24- | Write the output of the following code fragment.
import pandas as pd
serl=pd.Series(range(5.25,50,10.25),
index=[','b'/a'/a',b')) |
print(serl) |
print(ser!['a'])
print(serl[’b')) |
b 46.25
Q.25- | Considera series object s10 that stores the
number of students in each section of class 12 as
shown below. First two sections have been given
task for selling tickets @ Rs.100/- per ticket as a
part of social experiment. Write code to create
the series and display how much section A and B
have collected.
A 39 OUTPUT: . .
B31 Amount collected by Section A and B (in Rs.)
A 3900.0,
Cc 32 B 3200.0
Dos Gtype: £10832
E 35
Q.26- | Consider the series sas given below
0 2.50
1 1745
2 20.25
3 87.25
4 33.76
What will be the output after executing the
following:
Q27- | Consider the following code-
import pandas
‘s1=pandas.Series((2,3,4,5,6),index=|
print(s1)
What will be the output after executing the code,
. 2.00
b 345.60
je -14.65,
id -14.65
le 6.00
dtype: floatedCon: the Series object s12 that stores th
contribution of each section, as sh 7
ric own below:
B 8000
Cc 5400
D 3400
Write code to modify the amount of section ‘A’
the changed object.
as 8800 and for section 'C' and 'D' as 7700. Print
wracoer 6
5 €
g
BZes "veu0ca F
388-3883
s3ss88ss 5
streams( ‘Science’, ‘Commerce’ and 'Humanities')
are stored in two series objects el and c12.
write code to find total number of students in
class 11 and 12,, stream wise.
Q.29. | A Series object trainingdata consists of 2000
ows of data. Write a program to print (i) First
100 rows of data (ii) Last 5 rows of data
‘Q.30- | Consider the following Series s3- 0
a 1s 2
b 30 3
© 45 ‘
d 60 deype:
e 75 2
‘Now create the above series and find the output A
of the following commands- ‘
i) print(s3+3) ii) print(s3*2) aeeat
iii) print(s3>3.0) _ iv) print(s3[s3>3.0)) :
é
Seype: book
ors
a so
ors
deype: “froatse
Q.3I- | Consider the Series object s12 that stores the
contribution of each section, as shown below: OUTPUT:
A 6700 A 6700
B 8000 B 8000
Cc 5400 type: int64
D 3400
Write code to create the series and display those
sections that made the contribution more than
Rs, 5600/-
@32- | Number of students in class 11 and 12 in threeQ34-
Consider the series s1 and s2 and s3-
si s2 $3
010 05 a 3
120 110 b 6
230 215 ¢ 9
340 320 d I
450 425 e 1
5 30
6 35
Now find the output of the following-
i) print(S1+S2)
ii) print(S1*S3)
iii) print(S1-S2)
‘Consider the Series object S12 that stores the
jown below
contribution of each section, as sh
D 6700
A 8000
B $400
Cc 3400
i) Write code to create the series and display all
its values sorted in descending order
ii) Write code to display all its indices sorted in
ascending order.
ints
Why is following code producing error while
working on Series object 13?
dtype
of students
67
rv
95
Total no.
Science
Commerce
Humani tic:
deype: inted
ourpuT:
° «13.0 red o (5e
2 Soe J: 333
2 oo 2 iso
3 maw 3 20.0 |