Series Important Questions Assignment Worksheet no 2
Question 1) Given the following Series S1 and S2:
Series1 Series2
A 1 A 15
B 2 B 14
C 3 C 16
D 4 D 18
Write the command to find the multiplication of series S1 and S2.
Question 2) Consider a given Series , Subject:
ENGLISH 75
HINDI 78
MATHS 82
SCIENCE 86
Write a program in Python Pandas to create this series.
Question 3) Consider the following Series object, “company” and its profit in Crores
TCS 350
Reliance 200
L&T 800
Wipro 150
i. Write the command which will display the name of the company having profit>250.
print(s1[s1>250])
ii. Write the command to name the series as Profit.
s1.name="Profit"
Question 4) Consider two objects a and b. a 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*5)
b. print(b*5)
Justify your answer.
a) list elements is repeated two times, because a list is replicated when multiplied by any number, it does not allowed vector operation.
b) Series allows vector operation, that is why each element of the series has been multiplied by 2.
Question 5) Given a Pandas series called Sample, the command which will display the last 3 rows is .
a. print(Sample.tail(3)) # correct Answer
b. print(Sample.Tail(4))
c. print(Sample.tails(6)
d. print(Sample.Tails(2))
Question 6) What will be the output of the following code?
import pandas as pd
series1 = pd.Series(6,index=range(0,5))
print(s)
Question 7) If series1 is having following data,
What would be the result of the command print(series1[3:6])?
Question 8) What will be the output of the following code?
import pandas as pd
import numpy as np
s1 = pd.Series(np.arange(10,50,10))
print(s1)
print (s1.ndim)
print(s1.shape)
print(len(s1))
Question 9) Consider the following Series ‘s’-
0 4.0
1 5.0
2 7.0
3 NaN
4 1.0
5 10.0
dtype: float64
(i) Write a Python code to add 1 to all the elements.
s=s+1
(ii) Write a code to replace all NaN with 0.
s=s.fillna(0)
Question 10) Predict the output of the following code.
import pandas as pd
import numpy as np
data = {'one':'a','two':'b','three':'c'}
s=pd.Series(data)
print(s)
print(s.size)
0 Comments