【问题标题】:Pandas returns error: 'Series' objects are mutable, thus they cannot be hashedPandas 返回错误:“系列”对象是可变的,因此它们不能被散列
【发布时间】:2021-03-12 16:24:02
【问题描述】:

我有一个问题,我试图在我的数据框中找到一个特定的值。但是我收到了这个错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-245-ded282cec75c> in <module>
----> 1 data.iloc(data['Amount'] == '11,99')

~\Anaconda3\lib\site-packages\pandas\core\indexing.py in __call__(self, axis)
    576 
    577         if axis is not None:
--> 578             axis = self.obj._get_axis_number(axis)
    579         new_self.axis = axis
    580         return new_self

~\Anaconda3\lib\site-packages\pandas\core\generic.py in _get_axis_number(cls, axis)
    396     @classmethod
    397     def _get_axis_number(cls, axis):
--> 398         axis = cls._AXIS_ALIASES.get(axis, axis)
    399         if is_integer(axis):
    400             if axis in cls._AXIS_NAMES:

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __hash__(self)
   1796 
   1797     def __hash__(self):
-> 1798         raise TypeError(
   1799             f"{repr(type(self).__name__)} objects are mutable, "
   1800             f"thus they cannot be hashed"

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

我该如何继续?

import pandas as pd 
import matplotlib.pyplot as plt
import numpy as np

data = pd.read_csv('Data.csv', sep = ';')

data.iloc(data['Amount'] == '11,99')

【问题讨论】:

  • 能否请您尝试 data[data['Amount'] == '11,99'] 并告诉。您还想将 Amount 与多个值进行比较还是 '11,99' 是一个值?
  • 嗨,它已经按照您的描述工作了。您可以想象我有一个包含交易数据的 csv 文件,金额是特定交易 ID 的金额。
  • Kudos..发布代码 sn-p 作为答案以供参考..很高兴它有效..!

标签: python pandas


【解决方案1】:

使用data[data['Amount'] == '11,99'] 它应该可以正常工作..!

【讨论】:

    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多