Reputation: 309
How would I find the value of a cell in column x
on the condition that the value of column B
in the same row is the list [0,1]
?
Each cell in columns A
and B
are lists of integers.
x y A B
0 ding ding [0, 1] [0, 0]
1 ding dong [0, 1] [0, 1]
2 ding ding [0, 1] [0, 0]
3 ding ding [0, 1] [0, 0]
4 ding dong [0, 1] [0, 1]
5 ding ding [0, 1] [0, 0]
6 ding ding [0, 1] [0, 0]
Upvotes: 2
Views: 869
Reputation: 863801
IIUC you can create Series
with same index as DataFrame
and compare it with column B
:
s = pd.Series([[0, 1]], index = df.index)
print s
0 [0, 1]
1 [0, 1]
2 [0, 1]
3 [0, 1]
4 [0, 1]
5 [0, 1]
6 [0, 1]
dtype: object
print df['B'] == s
0 False
1 True
2 False
3 False
4 True
5 False
6 False
dtype: bool
print df[df['B'] == s]
x y A B
1 ding dong [0, 1] [0, 1]
4 ding dong [0, 1] [0, 1]
print df.x[df['B'] == s]
1 ding
4 ding
Name: x, dtype: object
Upvotes: 2