【发布时间】:2020-06-27 10:41:52
【问题描述】:
我正在尝试从我的数据框中构建一个替换 http、https、com 和 www 的函数。
df
content Col2 Col3 Col4
[www,roger, that,com, http, great, hi, www] 89 78 40
[http, https,www,roger, http, for,com, http, you, bye, www] 93 94 30
and so one...there are 30,000 rows
并不是每一行都是我的数据集中列内容的列表
定义函数
def replace(df):
for row in df:
for index, item in enumerate(row):
# create string *and update row*
row[index] = item.replace("www", " ")
row[index] = item.replace("http", " ")
row[index] = item.replace("https", " ")
row[index] = item.replace("com", " ")
return df
调用函数
df['content']=replace(df['content'])
问题是 www 被替换了,但是 http、https 和 com 没有被替换。我做错了什么
【问题讨论】: