我有一个成对有多个列的数据帧:如果一列是值,那么相邻的列就是相应的计数。我想绘制一个柱状图,使用值作为变量x,并计算为频率。
例如,我有以下列:
Age Counts
60 1204
45 700
21 400
. .
. .
34 56
10 150
我希望我的代码将Age
值以十年的间隔存储在最大值和最小值之间,并从Counts
列中获取每个间隔的累积频率,然后绘制直方图。有没有办法用matplotlib来实现这一点?
我试过下列方法,但都没有成功:
patient_dets.plot(x='PatientAge', y='PatientAgecounts', kind='hist')
(patient_dets是以“PatientAge”和“PatientAgecounts”为列的数据帧)
可以使用pd.cut()将数据装箱,然后使用函数plot('bar')进行绘图
我想你需要^{} :
如果需要箱子,一个可能的解决方案是使用^{} :
相关问题 更多 >
编程相关推荐