簡體   English   中英

Python:“系列”對象是可變的,因此它們不能被散列

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM