stacked bar using data from YouTube

Viewed 57

I am fetching data from YouTube API to plot VideoCategories and the country in a stacked plot Bar chart:

I`m Trying:

country_category4 = df_AnzahlTag[['channelCountry', 'videoCategoryName']]
test5 = country_category4.set_index('channelCountry')['videoCategoryName'].value_counts()
test5.plot(kind='bar', stacked=True)
plt.show()

enter image description here

1 Answers

Just use unstack():

df.groupby('channelCountry')['videoCategoryName'].value_counts().unstack().plot(kind="bar", stacked="True")

plot: enter image description here

by category

df.groupby('videoCategoryName')['channelCountry'].value_counts().unstack().plot(kind="bar", stacked="True")

enter image description here

Maybe not that meaningful as I hoped, but at least if shown by language is clearly shows the dominance of the english language when it comes to Music

df.groupby('videoCategoryName')['videoTitleLanguage'].value_counts().unstack().plot(kind="bar", stacked="True")

enter image description here


This answer was posted as an edit to the question stacked bar using data from YouTube by the OP SemperVirens under CC BY-SA 4.0.

Related