-6

I have a problem with a column of my dataframe but I don't understand why there are trouble on my column cat.enter image description here

enter image description here

Corentin Moreau
  • 111
  • 1
  • 1
  • 12

2 Answers2

2

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)]
jpp
  • 159,742
  • 34
  • 281
  • 339
0
df_cat_tot['cat'].unique()

This will help you to recover from this error. Both syntaxes are correct.

ouflak
  • 2,458
  • 10
  • 44
  • 49
keerthi
  • 1
  • 2