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:


print ( df2.loc["Jiva"] )

print ( df2.loc["Jiva", "IQ"] )

print ( df2.loc["Jiva":"Tim" , "IQ" : "College"])

print (df2.iloc[0] )

print (df2.iloc[0, 5] )

print ( df2f2.ilocloc[0:2, 5:8] )


Answer =

Output:-

(a) Error
(b) Error
(c) Error
(d)
df2.iloc[0]
name         jiya
age            10
weight         75
height        4.5
siblings        1
gender          M
iq            130
married     False
college       NaN

(e)
df2.iloc[0,5]
'M'

(f)
df2.iloc[0:2,5:8]
     gender   iq  married
jiya      M  130    False
tim       M  105    False

Post a Comment

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

Previous Post Next Post