Home > Mobile >  How to plot from a list using pandas
How to plot from a list using pandas

Time:08-15

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?

CodePudding user response:

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.

  • Related