gpt4 book ai didi

python - 如何修复 TypeError : 'Series' objects are mutable, 因此它们无法被散列

转载 作者:行者123 更新时间:2023-12-01 00:14:12 25 4
gpt4 key购买 nike

我有以下 pandas 数据框 df:

Id    Version  Time
110 9016 NaN
110 9016 NaN
110 9016 NaN
110 9016 2019-10-18 14:19:05.180

当我运行此查询时:

df.query('Time.isna()').head()

..我收到此错误:

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

为什么会发生这种情况以及如何解决?可能与pandas和Python的版本有关?我使用 Pandas '0.25.3' 和 Python 3。

最佳答案

这里使用参数engine='python',因为传递的pandas函数isna不能与numexpr引擎一起使用。有关 pandas.eval 的文档中的更多信息:

engine : string or None, default ‘numexpr’, {‘python’, ‘numexpr’}

The engine used to evaluate the expression. Supported engines are

None : tries to use numexpr, falls back to python

'numexpr': This default engine evaluates pandas objects using numexpr for large speed ups in complex expressions with large frames.

'python': Performs operations as if you had eval’d in top level python. This engine is generally not that useful.

More backends may be available in the future.

<小时/>
df1 = df.query('Time.isna()', engine='python').head()
print (df1)
Id Version Time
0 110 9016 NaN
1 110 9016 NaN
2 110 9016 NaN

或者技巧NaN != NaN:

df1 = df.query('Time != Time').head()
print (df1)
Id Version Time
0 110 9016 NaN
1 110 9016 NaN
2 110 9016 NaN

关于python - 如何修复 TypeError : 'Series' objects are mutable, 因此它们无法被散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59436314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com