Created
May 2, 2017 02:01
-
-
Save jhconning/6e6fafa15af5c1f87237e7c50a20f4c3 to your computer and use it in GitHub Desktop.
pandas: list comprehension to drop columns that match condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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