Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫的字符串替换_Python_Pandas_Text Mining - Fatal编程技术网

Python 熊猫的字符串替换

Python 熊猫的字符串替换,python,pandas,text-mining,Python,Pandas,Text Mining,我需要用链接的其余部分替换以www.开头的单词。例如: www.stackoverflow.com 与 我在用熊猫。包含链接的列称为COL1。我有1000行。 我试过了 df.loc[df['COL1'].str.startswith('www.', na=False), 'NEW_COL'] 但我不知道我应该用什么来取代,以获取其余的链接 您能给我一些建议吗?您可以使用str.replace替换为regex模式: df['COL1'] = df['COL1'].str.replace(

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

www.stackoverflow.com 

我在用熊猫。包含链接的列称为COL1。我有1000行。 我试过了

df.loc[df['COL1'].str.startswith('www.', na=False), 'NEW_COL'] 
但我不知道我应该用什么来取代,以获取其余的链接

您能给我一些建议吗?

您可以使用str.replace替换为regex模式:

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