【发布时间】:2021-06-01 09:45:10
【问题描述】:
我有一个熊猫 df,它有 6 列,最后一列是 input_text。我想从df 中删除该列中包含非英文文本的所有行。我想使用langdetect的detect函数。
一些模板
from langdetect import detect
import pandas as pd
def filter_nonenglish(df):
new_df = None # Do some magical operations here to create the filtered df
return new_df
df = pd.read_csv('somecsv.csv')
df_new = filter_nonenglish(df)
print('New df is: ', df_new)
注意!其他 5 列是什么无关紧要。
另请注意:使用detect 很简单:
t = 'I am very cool!'
print(detect(t))
输出是:
en
【问题讨论】:
-
事实证明 langdetect 在大文档上速度很慢,所以任何方法都可以!
-
到底是什么问题?
-
"我想从 df 中删除该列中包含非英文文本的所有行。我想使用 langdetect 的检测功能。"
-
正如我所指出的,数据框中的值是无关紧要的。问题可以通过使用最后一个 input_column 来解决,这是一个字符串,正如我指定的那样。
标签: python pandas algorithm nlp nltk