小编zin*_*gsy的帖子

使用 python 数据框中的两列(值、计数)绘制直方图

我有一个数据框,其中有多列成对:如果一列是值,则相邻列是相应的计数。我想使用值作为x变量并计数作为频率来绘制直方图。

例如,我有以下列:

   Age    Counts
   60     1204
   45      700
   21      400
   .       .
   .       .
   34       56
   10      150
Run Code Online (Sandbox Code Playgroud)

我希望我的代码将Age最大值和最小值之间十年间隔的值进行分类,并从列中获取每个间隔的累积频率,Counts然后绘制直方图。有没有办法使用 matplotlib 来做到这一点?

我尝试了以下方法但没有成功:

patient_dets.plot(x='PatientAge', y='PatientAgecounts', kind='hist')
Run Code Online (Sandbox Code Playgroud)

( Patient_dets 是以 'PatientAge' 和 'PatientAgecounts' 作为列的数据框)

python plot matplotlib histogram pandas

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

histogram ×1

matplotlib ×1

pandas ×1

plot ×1

python ×1