首页 > 解决方案 > 使用来自 YouTube 的数据的堆积条形图

问题描述

我正在从YouTube API获取数据以进行绘图VideoCategories,并country在堆叠的绘图栏中 chart

我正在尝试:

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

在此处输入图像描述

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

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

阴谋: 在此处输入图像描述

按类别

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

在此处输入图像描述

 也许没有我希望的那么有意义,但至少如果用语言表现出来的话,就清楚地表明了英语在音乐方面的主导地位

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

在此处输入图像描述

标签: pythonpandasdataframeplot

解决方案


推荐阅读