Reputation: 844
Let say I have a dataframe called df
:
name X Y
0 John 1 1
1 Cindy 1 0
2 Ella 0 1
3 David 0 0
I would like to compare columns X
and Y
such that when they are both 1, the corresponding row is added to a new data frame called df2
.
The desired output of df2
would be this:
name X Y
0 John 1 1
Moreover, I would like to do the same when
Upvotes: 0
Views: 52
Reputation: 8768
Try this:
dfs = [y for x,y in df.groupby(['X','Y'])]
df2 = dfs[0]
df3 = dfs[1]
df4 = dfs[2]
df5 = dfs[3]
Upvotes: 2