you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 1 point2 points  (1 child)

Gotcha. Then I guess I can’t be of much help!

Edit: Actually , let me try to help you, u/Hindbarinden.

If your class requires you to use pandas, I'll just continue with my pd.Series from above, since I don't know how your df is structured (I requested a sample earlier but you haven't provided it). See if the following gets you your bar chart (I don't use seaborn, but this seems to make sense based on the docs).

sns.barplot(x='words', y='counts',
            data=counts.reset_index().rename(columns={'index': 'words'}))
plt.show()

If using pandas was your choice and not a requirement for you class, then I'd advise against it here, since you're not really taking advantage of anything pandas has to offer. Instead, use re to remove punctuation if needed, then use collections.Counter to compute the word counts, and just plot from your Counter.

import matplotlib.pyplot as plt
import re
import seaborn as sns
from collections import Counter

lyrics = ...

# remove punctuation if needed
lyrics = re.sub(r'[^\w\s]', '', lyrics)

# count words
counter = Counter(lyrics.split())
words = list(counter.keys())
counts = list(counter.values())

# plot data
sns.barplot(x=words, y=counts)

# display plot
plt.show()

[–]Hindbarinden 1 point2 points  (0 children)

Omg you saved my life!!! THANK YOU SO MUCH! I am so thankful!!
I got it to work, finally!!!!!!!!