【问题标题】:Python : 'Series' objects are mutable, thus they cannot be hashedPython:“系列”对象是可变的,因此它们不能被散列
【发布时间】:2020-05-04 11:33:03
【问题描述】:

我有一个 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

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

【问题讨论】:

    标签: python tuples series hashable


    【解决方案1】:

    尝试这样做:

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

    【讨论】:

    • 如果您有很多重复,则对唯一的进行操作,然后将结果重新加入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2021-01-17
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    相关资源
    最近更新 更多