T
T
Timebird2018-02-21 15:37:02
Python
Timebird, 2018-02-21 15:37:02

How to filter dataframe?

Let's say I have multiple columns in a dataframe. Two columns can contain the same values ​​on the same lines.
Question: what function is needed to filter these lines?
Example.
Before filtering: 5a8d70172d1f1040657296.png
After filtering: 5a8d70228f96a230643962.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-02-21
@Timebird

On a tip Ilya :
gist

screenshot
5a8d8bdab9705038386336.png

I
Ilya, 2018-02-21
@hugga

If you need to include all columns then:

df = pd.DataFrame()
df[df.nunique(axis=1) == 1]

if only on selected columns then:
subset = [0, 1]
df[df[subset].nunique(axis=1) == 1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question