Search code examples
pythontuplesserieshashable

Python : 'Series' objects are mutable, thus they cannot be hashed


I have a DataFrame df with text as below :

        |---------------------|-----------------------------------|
        |      File_name      |     Content                       | 
        |---------------------|-----------------------------------|
        |          BI1.txt    |  I am writing this letter ...     |
        |---------------------|-----------------------------------|
        |          BI2.txt    |  Yes ! I would like to pursue...  |
        |---------------------|-----------------------------------|

I would like to create an additional column which provides the syllable count with :

       df['syllable_count']= textstat.syllable_count(df['content'])

The error :

           Series objects are mutable, thus they cannot be hashed

How can I change the Content column to hashable? How can I fix this error? Thanks for your help !


Solution

  • Try doing it this way:

    df['syllable_count'] = df.content.apply(lambda x: textstat.syllable_count(x))