我使用以下命令将我的表聚合到下面的表中
test_df = countData_df
stackedTable = test_df.reset_index().pivot_table(values='volume', index=['address', 'direction'],
aggfunc='sum')

不,我想创建一个条形图,条形图上有四种不同方向的颜色。每个条形图只能有两个选项:N或S;E或W
所以我完成了这行代码
test_df.reset_index().pivot_table(values='volume', index=['address', 'direction'],
aggfunc='sum').plot(kind = 'bar', stacked = True, color = ['b','g','r','m'])但是它显示如下

发布于 2021-05-09 12:31:44
代码就快写好了。要修复绘图,您需要取消堆叠方向。在本例中,方向是索引的一部分,但它应该是体积的某种分组元素。
test_df.reset_index().pivot_table(values='volume', index=['address', 'direction'],
aggfunc='sum').unstack("direction").plot(kind = 'bar', stacked = True, color = ['b','g','r','m'])发布于 2021-05-09 12:09:25
df = df[['direction', 'volume']]
df = df.groupby('direction').sum()https://stackoverflow.com/questions/67454167
复制相似问题