Q. Consider the following code that creates two dataframes:
ore1 = pd.DataFrame(np.array([[20,35,25,20], [11,28,32, 29]]), columns = ['iron', 'magnesium', 'copper', 'silver'])
ore2 = pd. Dataframe(np.array([[14, 34, 26, 26], [33, 19, 25, 23]]), columns = ['iron', 'magnesium', 'gold', 'silver'])
What will be the output produced by the following code fragments:
(a)
print(ore1 + ore2)
ore3 = ore1.radd(ore2)
print(ore)
(b)
print (ore1 - ore2)
ore3 = ore1.rsub(ore2)
print(ore3)
(c)
print (ore1 * ore2)
ore3 = ore1.mul(ore2)
print (ore3)
(d)
print (ore1 / ore2)
ore3 = ore1.rdiv(ore2)
print(ore3)
Answer =
(a)
print(ore1+ore2)
copper gold iron magnesium silver
0 NaN NaN 34 69 46
1 NaN NaN 44 47 52
ore3=ore1.radd(ore2)
print(ore3)
copper gold iron magnesium silver
0 NaN NaN 34 69 46
1 NaN NaN 44 47 52
(b)
print(ore1-ore2)
copper gold iron magnesium silver
0 NaN NaN 6 1 -6
1 NaN NaN -22 9 6
ore3=ore1.rsub(ore2)
print(ore3)
copper gold iron magnesium silver
0 NaN NaN -6 -1 6
1 NaN NaN 22 -9 -6
(c)
print(ore1*ore2)
copper gold iron magnesium silver
0 NaN NaN 280 1190 520
1 NaN NaN 363 532 667
ore3=ore1.mul(ore2)
print(ore3)
copper gold iron magnesium silver
0 NaN NaN 280 1190 520
1 NaN NaN 363 532 667
(d)
print(ore1/ore2)
copper gold iron magnesium silver
0 NaN NaN 1.428571 1.029412 0.769231
1 NaN NaN 0.333333 1.473684 1.260870
ore3=ore1.rdiv(ore2)
print(ore3)
copper gold iron magnesium silver
0 NaN NaN 0.7 0.971429 1.300000
1 NaN NaN 3.0 0.678571 0.793103
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )