ProgSky ProgSky - 3 years ago 195
Python Question

python dataframe query with spaces in column name

I want to filter dataframe using query

ExcludeData= [1,3,4,5]
dfResult.query('Column A in @ExcludeData')

How do I use Column A in query without renaming it ?

Answer Source

I wouldn't use query function. I would use the square bracket notation:

dfResult = dfResult[dfResult['Column A'].isin(ExcludeData)]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download