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
Predict the output of following code (it uses below given dictionary my_di).
my_di = {"name" : ["Jiya", "Tim", "Rohan"], "age" : np.array([10, 15, 20]), "weight" : (75, 123, 239), "height" : [4.5, 5, 6.1], "siblings" : 1, "gender" : "M"}df = pd.DataFrame(my_di) print(df)Consider the same dictionary my_di in the previous question (shown below), what will be the output produced by following code ?
my_di = {"name" : ["Jiya", "Tim", "Rohan"], "age" : np.array([10, 15, 20]), "weight" : (75, 123, 239), "height" : [4.5, 5, 6.1], "siblings" : 1, "gender" : "M"}df2 = pd.DataFrame(my_di, index = my_di["name"]) print(df2)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 :
df2["IQ"] = [130, 105, 115] df2["Married"] = False print(df2)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 :