简体   繁体   English

Python:“系列”对象是可变的,因此它们不能被散列

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

I have a DataFrame df with text as below:我有一个 DataFrame df,文本如下:

        |---------------------|-----------------------------------|
        |      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 !谢谢你的帮助 !

Try doing it this way:尝试这样做:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 系列对象是可变的,因此它们不能在 Python pandas 数据帧上散列 - Series objects are mutable, thus they cannot be hashed on Python pandas dataframe Python 和 Pandas:“系列”对象是可变的,因此它们不能被散列 - Python & Pandas: 'Series' objects are mutable, thus they cannot be hashed pandas Python Series对象是可变的,因此它们不能在查询方法中进行散列 - pandas Python Series objects are mutable, thus they cannot be hashed in query method 类型错误:“系列”对象是可变的,因此它们不能被散列 - TypeError: 'Series' objects are mutable, thus they cannot be hashed “系列”对象是可变的,因此它们不能被散列 - 'Series' objects are mutable, thus they cannot be hashed 'Series'对象是可变的,因此它们不能在调用to_csv时出现散列错误 - 'Series' objects are mutable, thus they cannot be hashed error calling to_csv 如何修复 TypeError:'Series' 对象是可变的,因此它们不能被散列 - How to fix TypeError: 'Series' objects are mutable, thus they cannot be hashed Pandas loc 错误:“系列”对象是可变的,因此它们不能被散列 - Pandas loc error: 'Series' objects are mutable, thus they cannot be hashed 键控错误:“系列”对象是可变的,因此它们不能被散列 - Keying Error: 'Series' objects are mutable, thus they cannot be hashed Pandas 返回错误:“系列”对象是可变的,因此它们不能被散列 - Pandas returns error: 'Series' objects are mutable, thus they cannot be hashed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM