KnowledgeBoat Logo
|

Informatics Practices

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'])

Python Pandas

3 Likes

Answer

Jiya      75
Tim      123
Rohan    239
Name: weight, dtype: int64
123

Working

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'.

Answered By

1 Like


Related Questions