亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在seaborn中將1行數據框繪制為條形圖?

如何在seaborn中將1行數據框繪制為條形圖?

精慕HU 2021-08-17 10:26:19
我不明白,它想要從數據框中繪制什么。我有一個數據框并試圖繪制它。目標是每列有一個酒吧。但我不能。我嘗試了各種組合:#df = df.transpose()sns.barplot(y=df.index.values, x=df.values, order=df.index)
查看完整描述

2 回答

?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

嘗試使用meltpandas 中的函數將此寬格式更改為長格式。

long_df = pd.melt(df)
sns.barplot(y = long_df.variable, x = long_df.value)


查看完整回答
反對 回復 2021-08-17
?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

使用 seaborn.barplot 繪圖


    import pandas as pd

    import seaborn as sns

    sales = {'Tony': 103,

     'Sally': 202,

     'Randy': 380,

     'Ellen': 101,

     'Fred': 82

    }


    #making dict to 1 row DataFrame

    df = pd.DataFrame(sales, index=[0])


    #flattening the values to be compliant with 

    #barplot method of seaborn and columns of dataframe

    

    values = df.values.flatten()

    sns.barplot(x = df.columns,y=values)

您的數據唯一的問題是您需要將其展平以使其兼容并使用 barplot 的上述參數


查看完整回答
反對 回復 2021-08-17
  • 2 回答
  • 0 關注
  • 210 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號