educative.io

Educative

Solution of Summing and Swapping

Is the solution in this topic correct?
The output of the solution is the following:
0 1 2 3 4 row_sum
0 98.0 56.0 12.0 18.0 12.0 122.0
1 91.0 71.0 98.0 46.0 34.0 80.0
2 49.0 11.0 33.0 90.0 74.0 102.0
3 24.0 9.0 64.0 53.0 7.0 108.0
4 30.0 49.0 4.0 32.0 6.0 80.0
col_sum 110.0 132.0 101.0 71.0 53.0 NaN

Witch is different from the output of my own code:
0 1 2 3 4 row_sum
0 98.0 56.0 12.0 18.0 12.0 110.0
1 91.0 71.0 98.0 46.0 34.0 132.0
2 49.0 11.0 33.0 90.0 74.0 101.0
3 24.0 9.0 64.0 53.0 7.0 71.0
4 30.0 49.0 4.0 32.0 6.0 53.0
col_sum 122.0 80.0 102.0 108.0 80.0 NaN

I think mine is correct.
And my code is:
def Sum_Swap_2(df):
row_min = df.min(axis = 1)
col_min = df.min(axis = 0)
row_max = df.max(axis = 1)
col_max = df.max(axis = 0)
df[‘row_sum’] = row_min + row_max
df.loc[‘col_sum’] = col_min + col_max

return df

Just confusing about it. Can anyone help me with it? Thanks.

Hi Tsu_Hsin ,

This is Maisam Shah from Educative.

Your solution is correct but incomplete. The challenge is to swap the row and column after computing their values. Currently, your solution only calculates the values for the new row and column but doesn’t swap them.
You can refer to the challenge statement here to clarify any other doubts.

We hope Educative has inspired you to further your learning.

Best Regards,
Maisam Shah | Developer Advocate
educative.io