-1
train = train.columns.apply(lambda x : train.drop([x],axis=1) if train[x].var() <100)

if a certain columns's var is lower then n i want to drop that column.
let say column x's var is lower then 100 then I want to drop the column

1 Answers1

2

In pandas we can do

df=df.loc[:,~df.var(axis=0).lt(100)].copy()
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Beat me to the answer, nice job! Also good to see that they are not reassigning it to the same dataframe and vectoring the answer rather than using the "silver bullet" – Edeki Okoh Feb 08 '20 at 00:01
  • 1
    Why the `.copy()`? – AMC Feb 08 '20 at 00:35
  • @AMC in case he need additional modify with the df, then will have the setcopy warning https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas – BENY Feb 08 '20 at 03:26