2

我的代码:

for column_name, column_data in summary_words.iteritems():
    if column_name != "summary" and column_name != "text" and column_name != "score" and column_name != "helpfulness":
        summary_words[column_name] = summary_words["summary"].str.count(column_name)

其中 summary_words 是 pandas 数据框,“summary”是该数据框中的一列。当我运行代码时,我收到此错误:

AssertionError:管理器项目的数量必须等于块项目管理器项目的联合:6004,#tot_items:6005

有谁知道为什么我会收到此错误以及如何解决它?

great   my  This    love    you best    and will    favorite    watch   ... step    succeeds    judge   (who    strictly    things, helpfulness score   summary text
0   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 100.0   3   "There Is So Much Darkness Now ~ Come For The ...   Synopsis: On the daily trek from Juarez, Mexic...
1   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 100.0   3   Worthwhile and Important Story Hampered by Poo...   THE VIRGIN OF JUAREZ is based on true events s...
2   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 80.0    5   This movie needed to be made.   The scenes in this film can be very disquietin...
3   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 100.0   3   distantly based on a real tragedy   THE VIRGIN OF JUAREZ (2006)<br />directed by K...
4   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 100.0   3   "What's going on down in Juarez and shining a ...   Informationally, this SHOWTIME original is ess...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
99995   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 0.0 5   A Great Collection! Gave this for a friends birthday and she LOVES...
99996   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 0.0 5   TOOOOO FUNNY    I had not seen the MP guys for years. I have o...
99997   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 0.0 5   monty python    this is the best flying circus that monty pyth...
99998   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 0.0 5   Python at its best and purest!  If you are a serious Monty Python fan, then th...
99999   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 0.0 5   Monty Python 16 DVD set I got this as a Christmas gift for my son - th...
4

2 回答 2

5

summary您的特殊用途关键字(如和)很可能helpfulness与您正在分析的词汇表中的单词发生冲突。

您应该能够通过查看长度来快速检查这一点:

len(summary_words.columns)
len(set(summary_words.columns))

在. _ _pd.concat

于 2020-04-16T01:06:23.730 回答
0

我有一个非常相似的问题。错误是:“管理器项的数量必须等于块项的联合#管理器项:11,#tot_items:9”这是因为我插入的列比我数据集中实际存在的列多。换句话说,我之前删除了 2 列。所以这个错误是合乎逻辑的,因为只剩下 9 列了。

于 2020-11-29T12:34:41.893 回答