簡體   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