'''
import pandas as pd
import re
articles_data = pd.read_csv('C:/Users/amrit/Downloads/data.csv')
print(articles_data.apply(lambda x: sum(x.isnull())))
articles_nonNull = articles_data.dropna(subset=['text'])
articles_nonNull.reset_index(inplace=True)
def clean_text(text):
#Make text lowercase, remove text in square brackets,remove \n,remove punctuation and
remove words containing numbers.
text = str(text).lower()
text = re.sub('<.*?>+', '', text)
text = re.sub('[%s]' % re.escape(string.punctuation), '', text)
text = re.sub('\n', '', text)
text = re.sub('\w*\d\w*', '', text)
return text
articles_nonNull['text_clean’] = articles_nonNull['text']
.apply(lambda x:clean_text(x))
'''我试图使用这段代码对我的数据进行预处理,并在文章_nonNull‘’text_clean‘中的最后两行中继续点击“无效语法错误”。有人能帮上忙吗?为什么会这样?
我是NLP的新手,这是我第一次处理一个非常大的非结构化数据集。
发布于 2022-06-05 09:59:45
在“‘text_clean’”的"]“前面有一个无效的字符,还可以使用反斜杠"\”来指示在下一行上继续语句,这应该有效:
articles_nonNull['text_clean'] = articles_nonNull['text'] \
.apply(lambda x:clean_text(x))https://stackoverflow.com/questions/72506288
复制相似问题