分配与熊猫无声地失败

时间:2017-01-26 14:11:38

标签: python pandas

我和熊猫有一个非常奇怪的问题。

在最后一行,我得到一个KeyError。 Pandas无法检索self.Attitudes [user],尽管事实上它应该在前一行设置。

有人可以提出可能出错的地方吗?

https://sourceforge.net/p/commonground/code/HEAD/tree/CommonGround.py

修改

def add_document(self,user,uri,document):
    """Calculates the sentiment score, and topic vector for the document,
       and updates the users's attitude vector"""

    self.Sentiments.loc[(user,uri)]=sum([emotion['compound'] 
                                        for emotion in (self.vader.polarity_scores(sentence)
                                                        for sentence in sentence_splitter.split(document))])
    self.Topics.loc[(user,uri),:]=pandas.Series(dict(self.model[self.get_features(document)]))
    self.Topics.fillna(0.0,inplace=True)
    self.Attitudes.loc[user]=self.Sentiments.loc[user].dot(self.Topics.loc[user])
    self.modulus.loc[user]=numpy.linalg.norm(self.Attitudes[user])

self.Sentimentsself.modulusSeries个对象。 self.Topicsself.AttitudesDataFrame个对象。

self.Sentimentsself.Topics具有层次结构索引(每个2级)。

0 个答案:

没有答案