How to Reference a Pandas Column that has a dot in the name
You cannot use the df.Content.xyz
notation to access the column. You can only reference the columns using df['Content.xyz']
df = pd.DataFrame([1,2], columns = ['Content.xyz'])
print(df['Content.xyz'])
0 1
1 2
From the .query()
docs:
New in version 0.25.0.
You can refer to column names that contain spaces by surrounding them in backticks.
For example, if one of your columns is called
a a
and you want to sum it withb
, your query should be`a a` + b
.
So that answers the second part of your question; you can use backticks around the column name to escape whitespaces in its name.
Unfortunately this only works for spaces right now and not yet for dots or other special characters. It is currently an open issue which is being worked on (https://github.com/pandas-dev/pandas/issues/27017) and might be fixed soon in a next release.