求助,我正在做机器学习相关问题,现在我爬取得原始数据需要进行清洗,如下:
我希望能使用pandas库遍历每一行,然后将text中包含的keywords列字符串全部清理掉,请问我该怎么做,我目前做到的成果如下,似乎没有结果:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2022/12/4 1:22
# @Author : CherryWh1te
# @Site : www.mozac.tech
# @File : csv_tester.py
# @Software: PyCharm
import pandas as pd
df = pd.read_csv("./data/origin/2022-11-12_Hot_topic.csv")
df = df.dropna(axis=0,how='any')
for index,row in df.iterrows():
text = str(row['text']).replace(row['keywords'],"")
row['text'] = text.replace("#", "")
df.to_csv("./data/processed/cleaned_2022-11-12_Hot_topic.csv",index=False)