I am trying to remove "0" and ":" from a column in a dataframe. The code I use is,
df_Main["Call Length"].str.replace(":", "")
df_Main["Call Length"].str.replace("0", "")
df_Main
The result does not remove "0" and ":" How can I go about this?
CodePudding user response:
You're missing to assignment of the replacement back to the original column:
df_Main["Call Length"] = df_Main["Call Length"].str.replace(":", "")
df_Main["Call Length"] = df_Main["Call Length"].str.replace("0", "")
df_Main
Though you can carry out this operation with only one application of replace
:
df_Main["Call Length"] = df["Call Length"].str.replace("[:0] ", "", regex=True)
CodePudding user response:
I would chain the two operations
df_Main["Call Length"].str.replace(":", "").str.replace("0", "")