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 \
As described here:
DataFrame.query()andDataFrame.eval()now supports quoting column names with backticks to refer to names with spaces (GH6508)
So you can use:
a.query('`a b`==5')
You cannot use pd.DataFrame.query if you have whitespace in your column name. Consider what would happen if you had columns named a, b and a b; there would be ambiguity as to what you require.
Instead, you can use pd.DataFrame.loc:
df = df.loc[df['a b'] == 5]
Since you are only filtering rows, you can omit .loc accessor altogether:
df = df[df['a b'] == 5]