One issue may be that python is not reading my back tick but instead treating it like a blank space:
'BACKTICK_QUOTED_STRING_PAY__LPAR_£M_SLASH_m_RPAR_'
^
"`PAY (£M/m)` < '3'"
^
I'm searching a CSV file with spaces within the columns (cannot change this naming decision).
I also need to use query as it's a dynamic query that changes depending on inputs. (I haven't included this code as I am just trying to get it to work manually)
I've tried this without '3' and nothing changed.
I'm performing a query with the following code:
data = df.query("`PAY (£M/m)` < '3'")
SyntaxError: Could not convert 'BACKTICK_QUOTED_STRING_PAY__LPAR_£M_SLASH_m_RPAR_' to a valid Python identifier.
Weirdly in the above error we have __ between the left parenthesis and the word PAY although below is the consoles output + the code written manually into the query.
Below is my CSV file exported and copied from a txt:
PAY (£M/m) INITIALS ID
2 ZE 223
5 NY 532
1 MA 122
3 ON 873
3 LS 235
df = df[df['PAY (£M/m)'] < 3]?£). I'm surprised no one else mentioned that. Have you considered replacing it with something likeGBP? The column could then bePAY (GBP M/m). That's the ISO 4217 code for it, btw..query()on that column name.