堆叠条形蟒蛇熊猫

时间:2021-04-15 15:58:53

标签: python pandas dataframe plot

我正在使用 YouTube Api 并希望在堆叠条形图中显示 VideoCategoriescountry
整列代表每个国家/地区的视频
并且该列应包含娱乐、音乐等视频类别

问题是我不明白我该怎么做

这是我最后一次尝试:

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

编辑:找到一个解决方案,只需使用 unstack()

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

结果图如下所示: enter image description here 或按类别 df.groupby('videoCategoryName')['channelCountry'].value_counts().unstack().plot(kind="bar", stacked="True") 分组: enter image description here

也许没有我希望的那么有意义,但至少如果用语言来表现的话,可以清楚地表明英语在音乐方面的主导地位 df.groupby('videoCategoryName')['videoTitleLanguage'].value_counts().unstack().plot(kind="bar", stacked="True")enter image description here

0 个答案:

没有答案