Drop Columns With Low Standard Deviation In Pandas Dataframe
Is there any way of doing this without writing a for loop? Suppose we have the following data: d = {'A': {-1: 0.19052041339798062, 0: -0.0052531481871952871, 1: -0.0022
Solution 1:
You can use the loc
method of a dataframe to select certain columns based on a Boolean indexer. Create the indexer like this (uses Numpy Array broadcasting to apply the condition to each column):
df.std() > 0.3
Out[84]:
A False
B False
C False
D False
E True
F False
G False
dtype: bool
Then call loc
with :
in the first position to indicate that you want to return all rows:
df.loc[:, df.std() > .3]
Out[85]:
E
-10.3027350 -0.3064021 -0.32698320.60257530.368600
Post a Comment for "Drop Columns With Low Standard Deviation In Pandas Dataframe"