Pandas 中的字符串替换

String replacements in Pandas

我需要用 link 的其余部分替换以 www. 开头的单词。例如:

www.whosebug.com 

whosebug.com

我正在使用 pandas。包含 link 的列称为 COL1。我有 1000 行。 我试过

df.loc[df['COL1'].str.startswith('www.', na=False), 'NEW_COL'] 

但我不知道我应该用什么替换才能使用 link 的其余部分。

你能给我一些建议吗?

您可以将 str.replace 与正则表达式模式一起使用:

df['COL1'] = df['COL1'].str.replace('^(www\.)', '')