Question: This is the header of the DataFrame

```
user_id       timestamp                group         landing_page                 converted

0   851104  2017-01-21 22:11:48.556739    control         old_page                       0
1   804228  2017-01-12 08:01:45.159739    control         old_page                       0
2   661590  2017-01-11 16:55:06.154213    treatment       new_page                       0
3   853541  2017-01-08 18:28:03.143765    treatment       new_page                       0
4   864975  2017-01-21 01:52:26.210827    control         old_page                       1

```

and the question for me is "what is The number of times the new\_page and treatment don't match?
and I used the following:

```
df[(df["group"]!= "treatment") & (df["landing_page"]=="new_page")]
df[(df["group"]== "treatment") & (df["landing_page"]!="new_page")]

```

but it counts them separately is there a better way to do it? or how to get the count of non-matched pairs?

Answer: 
How about:

```
df.groupby(['group','landing_page'])['user_id'].count()

```

which will give you:

```
group      landing_page
control    old_page        3
treatment  new_page        2

```

And if you want the number directly, you can do:

```
pd.DataFrame(df.groupby(['group','landing_page'])['user_id'].count()).sum()

```

which prints:

```
user_id    5

```
You could use logical xor `^` to check if the conditions are opposing:

```
df[(df["group"] == "treatment") ^ (df["landing_page"] =="new_page")]

```