Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jhconning/6e6fafa15af5c1f87237e7c50a20f4c3 to your computer and use it in GitHub Desktop.
Save jhconning/6e6fafa15af5c1f87237e7c50a20f4c3 to your computer and use it in GitHub Desktop.
pandas: list comprehension to drop columns that match condition
def drop_cols(df):
'''drop columns that don't vary'''
df.drop([ col for col in df.columns if (len(df[col].unique()) == 1)],
axis=1, inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment