First of all, please remember that replace
is case sensitive. Also, when chaining functions, the order is important.
"Â".lower().replace("Â", "") # "â"
"Â".replace("Â", "").lower() # ""
If the reason for the matter in question is a Mojibake encoding/decoding issue, you can try this quick fix with ftfy
library.
You can use it in conjunction with the rename
function.
import ftfy
def _change_column_name(val):
# fix mojibake
val = ftfy.fix_text(val)
# whatever data processing you need
return val.replace("Â", "").lower()
df.rename(columns=_change_column_name, inplace=True)
@tripleee is right, though. Maybe instead of quick fix you'd want to fix encoding/decoding errors in your source data.