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 produced by following code fragment :
Python Pandas
2 Likes
Answer
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
Working
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."
Answered By
1 Like
Related Questions
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 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 :
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])What is the output of the following code ?
d = {'col1': [1, 4, 3 ], 'col2': [6, 7, 8], 'col3': [9, 0, 1]} df = pd.DataFrame(d) print("Original DataFrame") print(df) print("New DataFrame :") dfn = df.drop(df.index[[1, 2]]) print(dfn)