简体   繁体   中英

Is there a way to remove a string character from all the values in a column consisting of strings?

I have a dataframe with one column consisting of string values like "asdb.sdsb". Is there a simple method/function where I can remove the "." in all the values in the column. Thanks.

Use .replace :

df = pd.DataFrame({"col1": ["asdb.asdb", "xyz.xyz"]})

Which is dataframe:

        col1
0  asdb.asdb
1    xyz.xyz

Then:

df["col1"] = df["col1"].str.replace(r"\.", "")
print(df)

Prints:

       col1
0  asdbasdb
1    xyzxyz

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