I am trying to produce a dataframe with these two conditional statements. I am using the | opperand or the 'or' opperand to seperate the conditional statements. There is not an issue with the conditional statements because when I run them seperately they work fine. Is there any other way I can seperate these conditional statements?
My code:
df = df2[(df2['TABNo'] == 0) & ~df2['IsBarrierTrial']] | df2[(df2['Position'] == 0)]
print(df)
Error:
TypeError: unsupported operand type(s) for |: 'float' and 'bool'
CodePudding user response:
Reindenting your statement:
df = (
df2[
(df2["TABNo"] == 0)
& ~df2["IsBarrierTrial"]
]
| df2[(df2["Position"] == 0)]
)
It looks like you're really looking for
df = df2[
(df2["TABNo"] == 0)
& (~df2["IsBarrierTrial"])
| (df2["Position"] == 0)
]
to select a bunch of items instead of having that one nested df2
indexing.
CodePudding user response:
Use or
/ and
instead of &
/ |
and check if error is resolved.