Your series contains other pd.Series
objects. This is bad practice. In general, you should ensure your series is of a fixed type to enable you to perform manipulations without having to check for type
explicitly.
Your error is due to pd.Series
objects not being hashable. One workaround is to use a function to convert pd.Series
objects to a hashable type such as 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()
This will help you to recover from this error. Both syntaxes are correct.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.