Suppose I have this Pandas Dataframe df:
A B
0 100 [2, 18, 20]
1 200 [3, 17]
2 200 [3, 17]
...
where column A is of type integer and column B is of type list of integers. And suppose I wish to count how many duplicate rows are there. In this small example of 3 rows, there's one duplicate row. So df.duplicated().sum() should output me 1 for this small example. But somehow it throws an error whenever I execute the command:
TypeError: unhashable type: 'list'
How I understand why this happens is that each value in the row becomes a key to an under the hood dictionary and a value would be counting how many of such keys exist in the dataframe. But since a type list cannot be a key in a dictionary, then this fails. Not sure if I understood it correctly.
But anyways, does anybody know a workaround method for finding how many duplicates there are in the dataframe that contains a column that has lists? And how to remove them?
Would converting the list to a string then dropping the list help? Although I would be using the list again in a later time, so that might be a hassle to go back to a list when I only have the strings. Any help is greatly appreciated. Thank you.