在 pandas 数据框中删除包含非英语单词的行 [英] dropping row containing non-english words in pandas dataframe
本文介绍了在 pandas 数据框中删除包含非英语单词的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我把这个推特语料库变成了熊猫数据框,我试图找到没有英文的tweet并将其从数据框中删除,所以我这样做了:
I turned this twitter corpus into pandas data frame and I was trying to find the none English tweets and delete them from the data frame, so I did this:
for j in range(0,150):
if not wordnet.synsets(df.i[j]):#Comparing if word is non-English
df.drop(j)
print(df.shape)
但是我检查形状,没有行掉落. 我使用drop函数是否错误,还是需要跟踪行的索引?
but I check the shape, no row was dropped. Am I using the drop function wrong, or do I need to keep track of the index of the row?
推荐答案
这是因为df.drop()
返回一个副本,而不是修改原始数据帧.尝试设置inplace=True
That's because df.drop()
returns a copy instead of modifying your original dataframe. Try set inplace=True
for j in range(0,150):
if not wordnet.synsets(df.i[j]):#Comparing if word is non-English
df.drop(j, inplace=True)
print(df.shape)
这篇关于在 pandas 数据框中删除包含非英语单词的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文