I have a pandas dataframe column that contains "tags" for SQL and I was curious to see what unique values would be for these tags.
For my pandas dataframe column if I use tags.m_tags.unique() this will through an error TypeError: unhashable type: 'list'
Manually looking at the data m_tags it is in list format looks like this:
[reheat, cmd]
[discharge, temp, air, sensor]
[flow, air, sensor]
[zone, temp, air, sensor]
Would anyone know how to get around this?
Just use explode() method and chain unique() method to it:
result=tags['m_tags'].explode().unique()
Now if you print result you will get your desired output
EDIT : If you have dictionary then use:
result=df['tags'].apply(lambda x:list(x.values())).explode().unique()
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With