[英]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.