10. Assume that required libraries (panda and numpy) are imported and dataframe df2 has been created as per questions 4 and 5 above. Predict the output produced by following code fragment :

print(df2[df2[“age”] > 12])
print(df2.head(2))
print(df2.tail(3))

# Solution

import pandas as pd, numpy as np

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”])
df2[“IQ”] = [130, 105, 115]
df2[“College”] = pd.Series([“IIT”], index=[“Rohan”])
print(df2[df2[“age”] > 12]) # All the rows where the age column has value greater than 12
print(df2.head(2)) # First two rows
print(df2.tail(3)) # Last three rows

# Output
name age weight height siblings gender IQ College
Tim Tim 15 123 5.0 1 M 105 NaN
Rohan Rohan 20 239 6.1 1 M 115 IIT
name age weight height siblings gender IQ College
Jiya Jiya 10 75 4.5 1 M 130 NaN
Tim Tim 15 123 5.0 1 M 105 NaN
name age weight height siblings gender IQ College
Jiya Jiya 10 75 4.5 1 M 130 NaN
Tim Tim 15 123 5.0 1 M 105 NaN
Rohan Rohan 20 239 6.1 1 M 115 IIT