This was my try. For example
df = pd.DataFrame({'a':[5,0,1,np.nan], 'b':[np.nan,1,4,3], 'c':[-3,-2,0,0]})
df.dropna(axis=1).max(axis=1,key=abs)
Filters out well the NaN
values but it gets 0 or negative values instead of the highes in absolute value
The result should be one column with
5
-2
4
3
The most straightforward and efficient way is to convert to absolute values, and then find the max. Pandas supports this with straightforward syntax (abs and max) and does not require expensive apply operations:
df.abs().max()
max()
accepts an axis
argument, which can be used to specify whether to calculate the max on rows or columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With