Hellow我有如下数据帧:
df= pd.DataFrame({"target1" : [10, 0, 15, 10], "target2" : [50, 0, 20, 0], "ID" : ["1", "2", "3", "4"]})
我需要创建一个绘图(条形图或饼图),它将显示ID中有多少%有target1,有多少target2,还有多少其他的(既不是target1也不是target2)
我需要的结果如下:
T1 75%,因为4个ID中有3个具有target1
T2 50%,因为4个ID中的2个具有target2
其他25%,因为4中的1既没有target1也没有target2
如果可能的话,我需要列和图例的百分比说明
我的解决方案
'ID'
,因为我们不想对该列进行计算0
(^{100
获取^{rot=1
,否则xticks
将是垂直的李>要对条形图进行注释,请执行以下操作:
patches
get_height
(百分比值),并通过添加'%'
符号将其格式化为适当的标签get_x
位置和{输出:
相关问题 更多 >
编程相关推荐