Home > Software engineering >  How to fix error: 'AnnAssign' nodes are not implemented in Python
How to fix error: 'AnnAssign' nodes are not implemented in Python

Time:12-01

I try to do following:

import pandas as pd
d = {'col1': [1, 7, 3, 6], 'col2': [3, 4, 9, 1]}
df = pd.DataFrame(data=d)

out = df.query('col1 > col2')

out=    col1  col2
1     7     4
3     6     1

This works OK. But when I modify column name col1 --> col1:suf

d = {'col1:suf': [1, 7, 3, 6], 'col2': [3, 4, 9, 1]}
    df = pd.DataFrame(data=d)
    
    out = df.query('col1:suf > col2')

I get an error:

'AnnAssign' nodes are not implemented

Is there easy way to avoid this behavior? Or course renaming headers etc. is a workaround

CodePudding user response:

The colon : is a special character in SQL queries. You need to enclose it in backticks.

Try this :

out = df.query('`col1:suf` > col2')

Output :

print(out)

   col1:suf  col2
1         7     4
3         6     1

CodePudding user response:

According to ValentinFFM's comment on this issue, you need to put a backtick quote around your column name like

df.query('`Column: Name`==value')
  • Related