![](/img/trans.png)
[英]Create multiple histograms, grouped by user from a large, single dataset in Python
[英]create a histograms for a row in a dataset with classification of 1 and 0
这是数据集:
我从数据库中创建了一个BMI
直方图,分类为 1 和 0。
df.hist(column='BMI',bins =30)
现在,我需要它看起来像这样:
分类就是结果。 如何使用 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.