[英]TypeError: 'Series' objects are mutable, thus they cannot be hashed problemwith column
您的系列包含其他pd.Series
对象。 这是不好的做法。 通常,您应该确保您的系列是固定类型,以便您无需显式检查type
即可执行操作。
您的错误是由于pd.Series
对象不可哈希。 一种解决方法是使用 function 将pd.Series
对象转换为可哈希类型,例如tuple
:
s = pd.Series(['one string', 'another string', pd.Series([1, 2, 3])])
def converter(x):
if isinstance(x, pd.Series):
return tuple(x.values)
else:
return x
res = s.apply(converter).unique()
print(res)
['one string' 'another string' (1, 2, 3)]
df_cat_tot['cat'].unique()
这将帮助您从此错误中恢复。 两种语法都是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.