在熊猫数据框中删除包含非英语单词的行

在熊猫数据框中删除包含非英语单词的行

问题描述:

我把这个推特语料库变成了熊猫数据框,我试图找到没有英文的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)