I have a dataframe containing a few columns with arrays. Here's a sample of one of the columns:
key arraylist
0 PROJECT-13051 [value1, value2, value4]
1 PROJECT-13050 [value2, value3, value4]
2 PROJECT-13049 [value1, value2, value3]
3 PROJECT-13048 [value3, value4, value5]
4 PROJECT-13047 [value1, value2, value5]
I pull this data from a sql database as comma seperated, then use the following to set as a list:
df[arraylist] = df[arraylist].apply(literal_eval)
I'd like group by the arraylist column and get the size of each value within the array:
df.groupby('arraylist').size()
This is resulting in the error TypeError: unhashable type: 'list'
I'd like to get an output like so:
arraylist
value1 3
value2 4
value3 3
value4 3
value5 2
dtype: int64
Any help would be greatly appreciated!