Q. Assume that required libraries (panda and numpy) are imported and dataframe df2 has been created as per questions.


Q. Predict the output of 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"}

Df = pd.DataFrame(my_di)

print(af)


and 

Q. Consider the same dictionary my_di, 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)

 

Predict the output produced by following code fragment:


df2["College"] = pd. Series (["IIT"], index=["Rohan"] )

print ( df2 )


Answer =

Output:-

              name  age  weight  height  siblings gender   iq  married college
jiya    jiya   10      75     4.5         1      M  130    False     NaN
tim      tim   15     123     5.0         1      M  105    False     NaN
rohan  rohan   20     239     6.1         1      M  115    False     iit

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post