select all columns with identical data

17 views
Skip to first unread message

Neal Becker

unread,
May 4, 2015, 2:03:27 PM5/4/15
to pydata
In a dataframe, I'd like to find all the columns where all the data (rows) are identical.  Any suggestions?

--
Those who don't understand recursion are doomed to repeat it

Paul Hobson

unread,
May 4, 2015, 2:15:53 PM5/4/15
to pyd...@googlegroups.com
If you know that you really want to use all the columns, I do something along these lines (untested):

df.loc[:, 'all_equal'] = df.apply(lambda row: all(row[0] == row), axis=1)

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages