我想遍历一个数据帧的列,并为每个列绘制一个堆叠的直方图,以区分两个组(其中death=0 vs 1)。如何将这些代码转换为迭代的代码?(bun_max是其中一个用作示例的列。)(另外,如何使图例起作用?)在
df1 = temp[temp['death'] == 0]
df2 = temp[temp['death'] == 1]
plt.figure()
plt.hist([df1.bun_max, df2.bun_max], bins=50, stacked=True, color=['b','r']);
plt.title(df1.bun_max.name)
plt.ylabel('ICU admits')
plt.xlabel(df1.bun_max.name)
plt.legend()
plt.show()
这就是我目前所拥有的。我得到一个错误:“TypeError:len()of unsize object”。所有列都是int或float。有助于理解错误的原因。在
^{pr2}$TypeError: len() of unsized object
我想出来了:
相关问题 更多 >
编程相关推荐