Hello I have the below dataframe and I am trying to calculate the absolute change for each City (row) and print the city name for the city with the largest value. I am able to get the absolute change but instead of getting the city name I am only able to get the index value. Is there a way I can get the city name instead of the index value. In the example below I am getting index value 3 instead of "Dallas".
df = pd.DataFrame({'City': ['Chicago', 'Atlanta', 'New York', 'Dallas'],
'col1': [10, 15, 80, 200],
'col2': [45, 75, 90, 5],
'col3': [25, 35, 60, 420],
'col4': [60, 105, 325, 55]})
Output:
City col1 col2 col3 col4
0 Chicago 10 45 25 60
1 Atlanta 15 75 35 105
2 New York 80 90 60 325
3 Dallas 200 5 420 55
Obtain Max Absolute Value of col1-col4
diff_row = df.max(axis=1) - df.min(axis=1)
print(diff_row.idxmax())
Current Output:
3
Desired Output:
Dallas