0

So I have a df containg the artist name and their position in a music chart(1 to 20) that looks like that: df

And i would like to have a barplot with multiple bars based on the charting position, but somehow it's not working so on the y-axis I would like to se 1 to 20 and on the x-axis to be the artist with the multiple barplots based on the charting. I tried this

plt.bar('Artist', 'Highest_Charting_Position',data=top_artists, color=sns.color_palette("flare", n_colors = 21))

as well as

top_artists = top_artists[['Highest_Charting_Position']].unstack().apply(pd.Series)
top_artists.plot.barh(rot=0, cmap=plt.cm.jet, fontsize=8, width=0.7, figsize=(8,4))

And when I run the code above I get this error: "None of [Index(['Highest_Charting_Position'], dtype='object')] are in the [columns]"

Does somebody know how to best do it?

buhtz
  • 10,774
  • 18
  • 76
  • 149
  • Does this answer your question? [How to explode a list inside a Dataframe cell into separate rows](https://stackoverflow.com/questions/32468402/how-to-explode-a-list-inside-a-dataframe-cell-into-separate-rows) – Vladimir Fokow Aug 15 '22 at 12:07
  • Could you send an example of how you would like your plot to look like? – Vladimir Fokow Aug 15 '22 at 15:01

2 Answers2

0

Explode each list into rows:

top_artists = top_artists.explode('Highest_Charting_Position')

Then you can plot however you like:

top_artists.plot.barh()
Vladimir Fokow
  • 3,728
  • 2
  • 5
  • 27
0

enter image description here

So my outcome should be like here in the picture to see okey Ariana Grade was on chart position 2, 4 and 5 for example and olivia rodrigo on position 1,4,5. My plot is only plotting it like that for only a few artists and not every artist which was on different chart positions.

  • This is not an answer to your question. This Information you posted here should be added to the question itself. – Rabinzel Aug 21 '22 at 04:54