0

I have the following pandas dataframe:

enter image description here

What is the best way to plot the word frequencies? I wanted to plot a histogram of the frequencies, it doesn't seem to work. Does anyone know how to get a histogram from here?

mozway
  • 194,879
  • 13
  • 39
  • 75
Laily
  • 11
  • 3

2 Answers2

0

Use plot.bar:

import matplotlib.pyplot as plt

df.set_index('words').plot.bar(rot=45)
plt.tight_layout()
plt.show()

histogram

Corralien
  • 109,409
  • 8
  • 28
  • 52
  • @Laily. Please can you check my answer if this solves your problem before I remove my post except if you accept the answer. – Corralien Sep 30 '21 at 16:28
  • Hey, thanks - you solved my problem. Just one more question would I be able to use plt.hist() at all here? @Corralien – Laily Sep 30 '21 at 19:02
  • An histogram is not the same thing as a bar plot. Try: `plt.hist(df['frequencies'])` – Corralien Sep 30 '21 at 19:42
0

I think what you are trying to get is:

df.plot(x='words',y='frequencies',kind='bar')
NicolasPeruchot
  • 439
  • 5
  • 9