I have a df that looks like this:
a b c
124 -3.09 -0.38 2.34
2359 4.81 0.51 -1.53
56555 -4.34 -0.64 2.31
96786 -3.33 -3.34 -7.62
I want to calculate the absolute max value of each row in a new column that keeps negatives as negatives. The closest I've gotten is with the following:
df['new_column'] = df.abs().max(axis = 1)
new_column
3.09
4.81
4.34
7.62
But I need the new column to keep the negative signs—i.e. to look like this:
new_column
-3.09
4.81
-4.34
-7.62
I've attempted a few things using abs().idxmax(), and am wondering if I need to find the location of the absolute max value, and then return the value in that location in the new column—just not sure how to do this. Thoughts?