我试图从我的数据帧中构建一个函数来替换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没有被替换。我做错了什么
您可以对列进行简单的列表理解:
样本数据
相关问题 更多 >
编程相关推荐