繁体   English   中英

Python 多个数据框到一张图中

[英]Python Multiple dataframes into one graph

因此,我能够根据下面发布的原始数据创建 3 个数据框。 另一个是女性数据框,但它在“性别”列下是“女性”,“费用”值不同。

DF1
children    charges
    0   12365.975602
    1   12731.171832
    2   15073.563734
    3   15355.318367
    4   13850.656311
    5   8786.035247

MALE DF (Female DF like this but with female under sex and different charge values)
children sex    charges
    0    male   12832.696736
    1    male   13273.522458
    2    male   16187.095325
    3    male   16789.167419
    4    male   13782.284829
    5    male   7931.658310

我想做的是将所有 3 个数据框组合成一个条形图。 一个女性酒吧,一个男性酒吧,以及一个男女结合的酒吧(DF1)。 我该怎么做? 谢谢!

我假设您想要一个包含男性、女性数量及其总和的条形图。 这是 plotty 的一个例子。 在 matplotlib 中,它非常相似。

male = pd.DataFrame([[1,2,3], [1,2,3]])
female = pd.DataFrame([[2,2,3], [2,2,3], [1,2,1]])
both = pd.DataFrame([[1,2,3], [1,2,3]])
go.Figure(
    data=[
        go.Bar(
            name='Male',
            x=['Male', 'Female', 'Both'],
            y=[male.shape[0], female.shape[0], female.shape[0]+male.shape[0]] 
        ),
        
    ]
).show()

https://plotly.com/python/bar-charts/

暂无
暂无

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

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