If a pandas dataframe has no spaces or special characters for column names the following command works great:
df.loc[df.Weight == "155", "Name"] = "John"
But what if the column name has special characters such as % and spaces are part of a column name. Replace Weight
in the previous command with:
% Population
What would the command be?
If I use the escape character , I receive a line continuation error. If I place the name in quotes, I get invalid syntax. The only way that I have found to run this command is to rename the column to a name without special characters, run the command, then rename the column back to its original name.
Thanks.