Python : 'Series' 对象是可变的,因此它们不能被散列

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

我有一个 DataFrame df,其文本如下:

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

我想创建一个额外的列来提供音节数:

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

错误:

           Series objects are mutable, thus they cannot be hashed

如何将内容列更改为可哈希?我该如何解决这个错误? 谢谢你的帮助 !

尝试这样做:

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