Imp Question of Series
Imp Question of Series
Questions Solutions
Q.1- Given the following Series1 import pandas as pd
A 100 Series1=pd.Series([100,200,300,400,500],index=['A','B','C','D','E'])
B 200 Series2=Series1*2
C 300 print(Series1)
D 400 print(Series2)
E 500 OUTPUT
Write the command to create above Series and
then double the value in series and store in
another series named Series2
Q.2- State whether True or False a. A series object is size mutable. (False)
a. A series object is size mutable. b. A Dataframe object is value mutable (True)
b. A Dataframe object is value mutable
OUTPUT:
Justification:
In Option a) list elements is repeated two times,
because a list is replicated when multiplied by any
number, it does not allowed vector operation.
In Option b) Series allows vector operation, that is why
each element of the series has been multiplied by 2.
OUTPUT:
Q.17- Consider the following Series ‘s’-
0 4.0 import pandas as pd
1 5.0 import numpy as np
s=
2 7.0 pd.Series([4,5,7,np.nan,1,10]
3 NaN )
4 1.0 print(s)
5 10.0 # add 1 to the series
dtype: float64 s=s+1
print(s)
(i) Write a Python code to add 1 to all s=s.fillna(0)
the elements. print(s)
(ii) Write a code to replace all NaN
with 0.
Q.26- Consider a series object s10 that stores the import pandas as pd
number of students in each section of class 12 as import numpy as np
shown below. First two sections have been given S10=pd.Series([39,31,32,34,35],index=['A','B','C','D','E'],
task for selling tickets @ Rs.100/- per ticket as a dtype=np.float32)
part of social experiment. Write code to create print("Amount collected by Section A and B (in Rs.)")
the series and display how much section A and B print(S10.head(2)*100)
have collected.
A 39 OUTPUT:
B 31
C 32
D 34
E 35
Q.27- Consider the series s4 as given below import pandas as pd
0 2.50 S4=pd.Series([2.50,17.45,20,25,87.25,33.76])
1 17.45 S4[0]=1.75
2 20.25 S4[2:4]= -23.74
3 87.25 print(S4)
4 33.76
What will be the output after executing the OUTPUT:
following:
S4[0]=1.75
S4[2:4]= -23.74
print(S4)
Q.29- Consider the Series object s12 that stores the import pandas as pd OUTPUT:
contribution of each section, as shown below: import numpy as np
A 6700 idx=[ 'A','B','C','D','E']
B 8000 contr=[6700,8000,5400,3
C 5400 400]
D 3400 s12=pd.Series(contr, idx)
Write code to modify the amount of section 'A' print(s12)
as 8800 and for section 'C' and 'D' as 7700. Print s12['A']=8800
the changed object.
s12[['C','D']]=7700
#or
s12.loc['C':'D']=7700
print(s12)