I have a pandas Data Frame df
of which elements of one column col
is a numpy.ndarray
of str
type. For example,
col
['I like tea', 'cricket ']
['basket ball', 'I like coffee', 'cricket ']
['I like tea', 'cricket ']
['basket ball', 'cricket ']
now I want to get number of such unique numpy.ndarray
in the col
to convert it into a categorical column with new column containing positive integer values for each unique numpy.ndarray
. When I'm using df['col'].unique
it is throwing following error
TypeError: unhashable type: 'numpy.ndarray'
How to find the number of unique elements for this numpy.ndarray
column?
edit:
The output I'm expecting is,
['I like tea', 'cricket '],['basket ball', 'I like coffee', 'cricket '],['basket ball', 'cricket ']
These are the unique lists in the column col
. I want these to be outputed.
edit 2:
When I converted each list of the col
into a tuple, I'm getting the required result. Why is this happening?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…