Use df.max() to index with.
In [19]: from pandas import DataFrame In [23]: df = DataFrame(np.random.randn(3,3), columns=['a','b','c']) In [36]: df Out[36]: abc 0 -0.928912 0.220573 1.948065 1 -0.310504 0.847638 -0.541496 2 -0.743000 -1.099226 -1.183567 In [24]: df.max() Out[24]: a -0.310504 b 0.847638 c 1.948065 dtype: float64
Next, we derive a logical expression from this:
In [31]: df.max() > 0 Out[31]: a False b True c True dtype: bool
Then you can index df.columns with this (this is called logical indexing):
In [34]: df.columns[df.max() > 0] Out[34]: Index([u'b', u'c'], dtype='object')
What you can finally go to DF:
In [35]: df[df.columns[df.max() > 0]] Out[35]: bc 0 0.220573 1.948065 1 0.847638 -0.541496 2 -1.099226 -1.183567
Of course, instead of 0, you use whatever value you want to use for clipping to delete.
source share