Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: TypeError: unhashable type: 'list' #3

Open
csantanaes opened this issue Jul 5, 2021 · 1 comment
Open

Error: TypeError: unhashable type: 'list' #3

csantanaes opened this issue Jul 5, 2021 · 1 comment

Comments

@csantanaes
Copy link

Can i help?

import nltk
a = nltk.FreqDist(HT_regular)
d = pd.DataFrame({'Hashtag': list(a.keys()),
'Count': list(a.values())})

selecting top 20 most frequent hashtags

d = d.nlargest(columns="Count", n = 20)
plt.figure(figsize=(16,5))
ax = sns.barplot(data=d, x= "Hashtag", y = "Count")
ax.set(ylabel = 'Count')
plt.show()


TypeError Traceback (most recent call last)
in ()
1 import nltk
----> 2 a = nltk.FreqDist(HT_regular)
3 d = pd.DataFrame({'Hashtag': list(a.keys()),
4 'Count': list(a.values())})
5

3 frames
/usr/lib/python3.7/collections/init.py in update(*args, **kwds)
653 super(Counter, self).update(iterable) # fast path when counter is empty
654 else:
--> 655 _count_elements(self, iterable)
656 if kwds:
657 self.update(kwds)

TypeError: unhashable type: 'list'

@Naztanzila
Copy link

you can try this for unhashable type : 'list'

import nltk

Convert the list into a tuple

HT_regular_tuples = [tuple(tag) for tag in HT_regular]

Create a frequency distribution

a = nltk.FreqDist(HT_regular_tuples)

Create a DataFrame from the frequency distribution

d = pd.DataFrame({'Hashtag': list(a.keys()), 'Count': list(a.values())})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants