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
CodePudding user response:
Short and simple way:
d.apply(lambda x: max(x)-min(x)).idxmax()
Output:
c
CodePudding user response:
A simple way of doing that is as follows
(d.max() - d.min()).idxmax()
CodePudding user response:
Try this:
d.columns[np.argmax(np.ptp(d, axis=0))]
Output:
'c'
