如何從我的資料框中的 bin 在 matplotlib(或 pandas)中制作條形圖?
我想要這樣的東西,在下面,x軸標簽來自我的資料框中的low, high(所以第一個刻度會讀取[-1.089, 0),y 值是percent我的資料框中的列。

這是一個示例資料集。資料集已經是這種格式(我沒有未刪減的版本)。
df = pd.DataFrame(
{
"low": [-1.089, 0, 0.3, 0.5, 0.6, 0.8],
"high": [0, 0.3, 0.5, 0.6, 0.8, 10.089],
"percent": [0.509, 0.11, 0.074, 0.038, 0.069, 0.202],
}
)
display(df)

uj5u.com熱心網友回復:
使用重新創建垃圾箱
uj5u.com熱心網友回復:
使用低、高列創建一個新列。
將低列和高列中的 int 值轉換為 str 型別,并以所需的[<low>, <high>)表示法設定新的 str。
df從那里,您可以使用直接創建條形圖df.plot.bar(),將新創建的列指定為 x,百分比指定為 y。
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.bar.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/438508.html
標籤:Python 熊猫 matplotlib 条形图
