繁体   English   中英

为数据集中的一行创建直方图,分类为 1 和 0

[英]create a histograms for a row in a dataset with classification of 1 and 0

这是数据集:数据集

我从数据库中创建了一个BMI直方图,分类为 1 和 0。

df.hist(column='BMI',bins =30)

直方图

现在,我需要它看起来像这样:

第 1 类和第 0 类的直方图

分类就是结果。 如何使用 python 创建 2 个单独的直方图,分类为 1 和 0。

您可以在matplotlib模块中使用subplots

像这样的东西:

import matplotlib.pyplot as plt

#Define axes and the figure. 
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(5, 3))

#Plot the left subplot: first filter df by outcome == 0 and then plot
df[df["Outcome"] == 0].hist(column = "BMI", bins= 30,  ax = axes[0])
#Right hand plot. 
df[df["Outcome"] == 1].hist(column = "BMI", bins= 30, ax = axes[1])

请参阅下面的随机数据图:

使用一些随机数据的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM