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 :
df2["IQ"] = [130, 105, 115]
df2["Married"] = False
print(df2)
Python Pandas
3 Likes
Answer
name age weight height siblings gender IQ Married
Jiya Jiya 10 75 4.5 1 M 130 False
Tim Tim 15 123 5.0 1 M 105 False
Rohan Rohan 20 239 6.1 1 M 115 False
Working
The code adds two new columns "IQ" with values [130, 105, 115] and "Married" with value "False" for all rows to DataFrame df2, then prints the DataFrame.
Answered By
3 Likes
Related Questions
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 :
print(df2["weight"]) print(df2.weight['Tim'])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 :
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 :
print(df2.loc["Jiya"]) print(df2.loc["Jiya", "IQ"]) print(df2.loc["Jiya":"Tim", "IQ":"College"]) print(df2.iloc[0]) print(df2.iloc[0, 5]) print(df2.iloc[0:2, 5:8])