Search code examples
pythonpython-3.xpandasdataframeiteritems

AssertionError: Number of manager items must equal union of block items # manager items: 6004, # tot_items: 6005


My code:

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)

where summary_words is a pandas dataframe, and "summary" is a column in that dataframe. When I run the code I get this error:

AssertionError: Number of manager items must equal union of block items manager items: 6004, # tot_items: 6005

Does anyone have any idea why I'm getting this error and how to fix it?

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...

Solution

  • It is very likely that your special-use keywords, like summary and helpfulness, are colliding with words in the vocabulary you are analyzing.

    You should be able to check this pretty quickly by looking at the lengths:

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

    See this SO Q&A for additional detail on the multiple columns issue, in the context of a pd.concat.