I have a dataframe with spaces in column names. I am trying to use query
method to get the results. It is working fine with \'c\' column but getting error for \
It is not possible yet. Check github issue #6508:
Note that in reality .query is just a nice-to-have interface, in fact it has very specific guarantees, meaning its meant to parse like a query language, and not a fully general interface.
Reason is for query
need string to be a valid python expression, so column names must be valid python identifiers.
Solution is boolean indexing:
df = df[df['a b'] == 5]