简体   繁体   中英

Remove characters from column

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

Output:

在此处输入图像描述

The result does not remove "0" and ":" How can I go about this?

我会链接这两个操作

df_Main["Call Length"].str.replace(":", "").str.replace("0", "")

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM