Reputation: 409
I have this df:
values = {'a':[1,2,3,4], 'b':[1,2,5,9], 'c':[10,1000,20,30]}
d=pd.DataFrame(values)
What's the best way to get the column with the highest spread between max and min values?
The output shoub be: c
because 1000 - 10
> 9 - 1
> 4 - 1
Upvotes: 0
Views: 46
Reputation: 153560
Try this:
d.columns[np.argmax(np.ptp(d, axis=0))]
Output:
'c'
Upvotes: 1
Reputation: 1885
A simple way of doing that is as follows
(d.max() - d.min()).idxmax()
Upvotes: 2
Reputation: 3076
Short and simple way:
d.apply(lambda x: max(x)-min(x)).idxmax()
Output:
c
Upvotes: 2