我正在尝试删除所有不属于法语的短语。我尝试使用 langdetect 库(不幸的是没有 pandas)
CSV 文件
message
Je suis fatiguée
The book is on the table
Il fait chaud aujourd'hui!
They are sicks
La vie est belle
脚本:
import csv
from langdetect import detect
with open('ddd.csv', 'r') as file:
fichier = csv.reader(file)
for line in fichier:
if line[0] != '':
message = line[0]
def detecteur_FR(message):
#We need to turn the column into a list of lists.
message_list = [comments for comments in message.split('\n')]
for text in message_list:
if detect(text) == 'fr':
message_FR = text
return message_FR
print(detecteur_FR(message))
我的输出:
None
Je suis fatiguée
None
Il fait chaud aujourd hui!
None
La vie est belle
我要:
Je suis fatiguée
Il fait chaud aujourd hui!
La vie est belle
如何删除“无”?
最佳答案
您只需在打印前添加一张支票:
result = detecteur_FR(message)
if result is not None:
print(result)
关于python - 从输出中删除 'None',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51668931/