Python 如何将数据转换为文本数据
我想制作一个简单的拼写更正系统,我有一个如下的数据场:Python 如何将数据转换为文本数据,python,pandas,nlp,Python,Pandas,Nlp,我想制作一个简单的拼写更正系统,我有一个如下的数据场: incorrect_word, correct_word scoohl,school watn,want frienf,friend “我等着去史酷尔” 我想通过将“不正确的单词”列中的不正确样本替换为“正确的单词”列中的正确样本(如果存在)来纠正这句话 我该怎么做? 我编写的示例代码不起作用 我想这样做: df = pd.DataFrame([['scoohl','school'], ['watn','want'], [
incorrect_word, correct_word
scoohl,school
watn,want
frienf,friend
“我等着去史酷尔”我想通过将“不正确的单词”列中的不正确样本替换为“正确的单词”列中的正确样本(如果存在)来纠正这句话 我该怎么做?
我编写的示例代码不起作用
我想这样做:
df = pd.DataFrame([['scoohl','school'], ['watn','want'], ['frienf','friend']], columns=['incorrect_word', 'correct_word'])
df.index = df['incorrect_word']
df.drop(columns=['incorrect_word'], inplace=True)
text_to_correct = "I watn to go scoohl"
words = text_to_correct.split(' ')
for c, w in enumerate(words):
if w in df.index:
words[c] = df.at[w,'correct_word']
words = ' '.join(words)
words
结果:
'I want to go school'
您好,这是非常基本的python,您可以用这种方式来完成
df['incorrect']=[x for x in df['Correct'] if len(x)>2]
您应该搜索lambda,列出压缩,应用和映射
谢谢。您显示的数据框与您使用的数据框似乎有不同的列。你能提供更多关于你正在使用的excel的细节吗?是的,我提供了一个简单的数据框作为上面代码的一个例子,你的权利@不幸的是,你对“我的问题”的回答完全错了,谢谢你@jaimeIm抱歉
df['incorrect']=[x for x in df['Correct'] if len(x)>2]