【发布时间】:2018-11-26 17:51:18
【问题描述】:
我想绘制此数据框,但出现错误。 这是我的 df:
6month final-formula Question Text
166047.0 1 0.007421 bathing
166049.0 1 0.006441 dressing
166214.0 1 0.001960 feeding
166216.0 2 0.011621 bathing
166218.0 2 0.003500 dressing
166220.0 2 0.019672 feeding
166224.0 3 0.012882 bathing
166226.0 3 0.013162 dressing
166229.0 3 0.008821 feeding
160243.0 4 0.023424 bathing
156876.0 4 0.000000 dressing
172110.0 4 0.032024 feeding
如何根据Question text 绘制堆积条形图?
我尝试了一些代码,但出现了错误。
dffinal.groupby(['6month','Question Text']).unstack('Question Text').plot(kind='bar',stacked=True,x='6month', y='final-formula')
import matplotlib.pyplot as plt
plt.show()
实际上我希望6month 列位于x-axis 中,y-axis 和Question text 中的final-formula 被堆叠。
所以在这里我有三种Question text,应该有三个堆叠条。和我一样4 month,总共有 4 个酒吧。
类似this 的东西,但我应用了这个但没有用。 我错过了什么吗?
这张图片没有堆叠。就像所有question text 都已经总结出来了。我希望每个Question Text 都有堆叠。
【问题讨论】:
标签: pandas matplotlib bar-chart data-visualization data-analysis