So I'm dropping rows based on column values. My df contains two specific columns that I'm filtering: ['Exclude', 'Lost Flag']. Both columns contain binary values. I dropped all rows where "Exclude" was 1 via:
df = df[df.Exclude !=1]
All is well. However, when I tried to do the same thing with "Lost Flag":
df = df[df.Lost Flag !=1]
I get SyntaxError on the column name. I've triple checked the column name, tried underscore, no space, and tried escaping the space using ``. Then I tried pd.query:
df = df.query('Lost Flag !=1')
And I got the same syntax error. I feel like I'm missing something obvious.
df['col name']for accessing columns, whether there are spaces or not. Unless you have space limitations on your script file for some unknown reason, changing to this notation can help resolve a whole lot of issues I've come across