CBSE Class 12 Informatics Practices Question 135 of 167

Python Pandas — I — Question 25

Back to all questions
25
Question

Question 19

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 of following code fragment :

print(df2["weight"])
print(df2.weight['Tim'])
Answer
Output
Jiya      75
Tim      123
Rohan    239
Name: weight, dtype: int64
123
Explanation

The given code creates a dictionary my_di. Then, a DataFrame df2 is created using the pd.DataFrame() constructor and passing the my_di dictionary and the my_di["name"] list as the index. The print() function is used to display the 'weight' column of the DataFrame df2 and the value of the 'weight' column for the row with index 'Tim'.