Professional Documents
Culture Documents
Series
Series
Series
T Tiger
L Lion
W Wolf
E Elephant
F Fox
dtype: object
Output:
9 Write a program to create a Series object using a dictionary that stores the
number of peoples in each states (any 4 states)
Ans: import pandas as pd
a = {‘Assam’:5000, ‘Nagaland’:6000, ‘Manipur’:4000, ‘Maharashtra’:8000}
b = pd.Series(a)
print(b)
10 Given a Series object s4. Write a program to change the values at its 3rd row
(index 2) and 4th row to 8700.
11 What will be the output for the following code?
import pandas as pd
import numpy as np
s=pd.Series(np.random.randn(3))
print(s.ndim)
(a)0 (b)1
(c)2 (d)3
Ans:(b) 1
12 Assuming the given series named ‘S1’, which command will be used to print 4 as
output?
Romit 87
Suresh 54
Sakshi 88
Madhu 44
(a)S1.index (b)S1.size
(c)S1.values (d)S1.ndim
13 Given the following series objects:
S1 S2
0 10 0 1
1 15 2 2
2 20 3 3
4 25 4 4
5 30 6 5
What will be the result of S1–S2?
14 To create an empty Series object, you can use:
(a) pd.Series(empty) (b) pd.Series(np.NaN)
(c) pd.Series( ) (d) all of these
Ans: (c) pd.Series()
15 Write a program to create a Series object using an ndarray that has 10 elements
in the range 15 to 50.
Ans: import pandas as pd
import numpy as np
a = pd.Series(np.linspace(15,50,10))
print(a)
16
17
18