且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在数据框列中删除字符串的子字符串?

更新时间:2023-11-14 22:51:46

您需要将修剪后的列分配回原始列,而不是进行子集设置,并且 str.replace 方法似乎没有 to_replace value 参数。而是使用 pat repl 参数:

You need to assign the trimmed column back to the original column instead of doing subsetting, and also the str.replace method doesn't seem to have the to_replace and value parameter. It has pat and repl parameter instead:

df["Date"] = df["Date"].str.replace("\s:00", "")

df
#   ID       Date
#0   1  8/24/1995
#1   2   8/1/1899