我有一个数据帧'dft',其中有两列'Month'(可以是一月到十二月)和'expensation'(该月的数据)。在
我正试图为这些数据创建一个堆叠的条形图,堆栈表示0-100;100-500和500+之间的支出
为了对这些值的数据帧进行排序,我编写了以下代码。在
small = dft[(dft['Expenditure'] < 100) & (dft['Expenditure'] > 0)]
medium = dft[(dft['Expenditure'] <= 500) & (dft['Expenditure'] >= 100)]
large = dft[(dft['Expenditure'] > 500)]
有没有一种方法可以直接从Pandas直接将这些数据帧绘制成一个堆积条形图?图表将有一个月的x轴和y轴的支出。在
把我的评论变成一个答案:不是拆分数据帧,而是添加一个新的列和限定符来堆栈(small,medium,large)。然后按新列旋转框架并使用stacked=True选项打印。在
欢迎来到StackOverflow!在
我试图创建一个简单的示例(使用原始给定数据)来解决您的案例。您还应该查看文档中的stacked_bar_chart。要转换月份并“填充”数据,可以使用以下方法:
相关问题 更多 >
编程相关推荐