Page 95 - Informatics_Practices_Fliipbook_Class12
P. 95
Ans. d. Name Age
0 Sapna 16
1 Anmol 18
2 Rishul 16
3 Sameep 19
21. Consider the following code: [2022]
import pandas as pd
Sl=pd.Series ( [23,24,35,56], index= [ 'a', 'b', 'c',d'])
S2=pd.Series ( [27,12,14,15],
index=[ 'b','y' ,'c','ab'])
df=pd.DataFrame (S1+S2)
print (df)
Output for the above code will be:
a. O b. O
a NaN a 50
ab NaN b 36
b 51.0 c 49
c 49.0 d 71
d NaN
y NaN
c. O d. O
b 50 a NaN
y 36 ab NaN
c 49 b NaN
ab 71 c NaN
d Nan
y Nan
Ans. a. O
a NaN
ab NaN
b 51.0
c 49.0
d NaN
y NaN
22. Sudhanshu has written the following code to create a DataFrame with boolean index: [2022]
import numpy as np
import pandas as pd
df=pd.DataFrame (data=[ [5,6,7]],index=[true, false, true])
print (df)
While executing the code, she is getting an error, help her to rectify the code:
a. df=pd.DataFrame([True,False, True], data=[5,6,7])
b. df=pd.DataFrame(data=[5, 6,7], index=[True, False, True])
c. df=pd.DataFrame([true,false, true],data=[5,6,7])
d. df=pd.DataFrame(index=[true,false, true],data[[5,6,7]])
Ans. b. df=pd.DataFrame(data=[5, 6,7], index=[True, False, True])
Data Handling using Pandas DataFrame 81

