【问题标题】:Is there any way to detect English words in a string in pandas有没有办法检测熊猫字符串中的英文单词
【发布时间】:2020-10-10 23:07:42
【问题描述】:

我有一个包含歌曲、歌手和歌词的数据框。有些歌曲的歌词不是英文的,但字母是拉丁字母。有什么方法可以将英语单词(具有英语含义)与非英语单词(由拉丁字母书写,但没有英语含义)分开。任何 Python 库或某种代码?我的主要目标是通过歌词进行情感分析。

【问题讨论】:

    标签: python pandas dataframe sentiment-analysis non-english


    【解决方案1】:

    python 中有一个库可以做到这一点,称为langdetect

    这是一个使用它的例子:

    >>> from langdetect import detect
    >>> detect("War doesn't show who's right, just who's left.")
    'en'
    >>> detect("Ein, zwei, drei, vier")
    'de'
    

    【讨论】:

    • 非常感谢 Fatemeh Rahimi :) 你的回答对我有很大帮助。
    • 但是Fatemeh,我需要你的帮助一次。如何从我的数据框中选择行,其中歌词检测为“en”? rslt_df = df[df['lyrics'].detect = "en"] 类似的东西
    • 欢迎您。您可以使用apply function from pandas。如果您的数据框,将此函数应用于所有行。然后您可以将输出放入另一列。 Example
    猜你喜欢
    • 2021-09-18
    • 2022-10-07
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多