I am trying to run a multiline query using df.query
but I seem to be getting the following error even after adding backslashes:
column = 'method'
idx = df.query(
f"""{column} == 'One' and \
number.notnull() and \
flag.isnull()""").index
My df looks like this:
df
'method' 'number' 'flag'
23 'One' 0 None
24 'One' 1 1
25 'Two' 1 None
I get this error:
ValueError: multi-line expressions are only valid in the context of data, use DataFrame.eval
I tried to use this answer to fix but am still getting the exact same error:
pandas dataframe multiline query
Can someone help explain why this does not work?
Thanks