CBSE Class 12 Informatics Practices Question 137 of 167

Python Pandas — I — Question 27

Back to all questions
27
Question

Question 21

Assume that required libraries (panda and numpy) are imported and dataframe df2 has been created as per questions 17 and 18 above. Predict the output produced by following code fragment :

df2["College"] = pd.Series(["IIT"], index=["Rohan"]) 
print(df2)
Answer
Output
        name  age  weight  height  siblings gender College
Jiya    Jiya   10      75     4.5         1      M     NaN
Tim      Tim   15     123     5.0         1      M     NaN
Rohan  Rohan   20     239     6.1         1      M     IIT
Explanation

The code snippet uses the pandas and numpy libraries in Python to create a DataFrame named df2 from a dictionary my_di. The DataFrame is indexed by names, and a new column "College" is added with "IIT" as the value only for the index named "Rohan."