I'm sorry it's probably a very silly question but I can't resolve the problem on my own.
I need to write a very large condition in a df.query() method to filter my data. But for some reason I have an error.
My code
data_normal = data.query('(total_area < 400) & (rooms < 10) & (living_area > 10) & (living_area < 200) \
& (kitchen_area > 5) & (kitchen_area < 40) & (celling_height >= 2.5) & (last_price < 200000000) \
& (last_price >= 1000000) & (floors_total < 30) & (days_exposition < 800) & (days_exposition > 5) \
& (cityCenters_nearest <= 52000) & (parks_nearest <= 1500) & (parks_nearest > 10)')
returning an error:
File "/tmp/ipykernel_306/3185002971.py", line 7 & (kitchen_area > 5) & (kitchen_area < 40) & (celling_height >= 2.5) & (last_price < 200000000) \
^ SyntaxError: EOL while scanning string literal
But my previous code
data_normal = data.query('(total_area < 400) & (rooms < 10) & (living_area > 10) & (living_area < 200) \
& (cityCenters_nearest <= 52000) & (parks_nearest <= 1500) & (parks_nearest > 10)')
does not catch any errors. I don't know why.
I tried to find quotation that caused this error but I still don't see it as if I'm blind. Help me please.
I've tried multi-line expression with like
data_normal = data.query('''(total_area < 400) & (rooms < 10) & (living_area > 10) & (living_area < 200) \
& (kitchen_area > 5) & (kitchen_area < 40) & (celling_height >= 2.5) & (last_price < 200000000) \
& (last_price >= 1000000) & (floors_total < 30) & (days_exposition < 800) & (days_exposition > 5) \
& (cityCenters_nearest <= 52000) & (parks_nearest <= 1500) & (parks_nearest > 10)''')
It might be an issue with multi-line query string and slashes. Maybe try to put it in one line first and then gradually split and make it more readable.
This worked for me: