首页 > 解决方案 > 使用 modin.pandas 应用更快的 pandas

问题描述

尝试使用 modin.pandas 将所有内核用于此应用功能

from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
# sentiment Score of essay
data = data.merge(data.essay.apply(lambda s: pd.Series({'neg':sid.polarity_scores(s)['neg'], 
                                                 'neu':sid.polarity_scores(s)['neu'],
                                                 'pos':sid.polarity_scores(s)['pos'],
                                                 'compound':sid.polarity_scores(s)['compound']})), 
           left_index=True, right_index=True)

它适用于默认的 pandas,但使用 modin 会引发此错误:

ValueError: can not merge DataFrame with instance of type <class 'modin.pandas.series.Series'>

文章是 DataFrame 中名为“data”的文本列

标签: pythonpandasnlpmodin

解决方案


正如这个问题的答案所暗示的那样,您可能会收到此错误,因为您正在将 apandas.Dataframe与 a合并modin.Series。对于您的示例,请尝试data使用modin.pandas.DataFrame(data).


推荐阅读