简体   繁体   English

使用 modin.pandas 应用更快的熊猫

[英]Faster pandas apply using modin.pandas

Trying to use all cores for this apply function using modin.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)

It works with default pandas, but using modin raises this error:它适用于默认的熊猫,但使用 modin 会引发此错误:

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

essay is text column in the DataFrame named "data" Essay 是 DataFrame 中名为“data”的文本列

As the answers to this question suggest, you are likely getting this error because you are merging a pandas.Dataframe with a modin.Series .正如这个问题的答案所暗示的那样,您可能会收到此错误,因为您正在将pandas.Dataframemodin.Series合并。 For your example, try converting data to a modin dataframe with modin.pandas.DataFrame(data) .对于您的示例,尝试使用modin.pandas.DataFrame(data)data转换为modin.pandas.DataFrame(data)帧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM