2017-04-24 152 views
1

是否有任何圖庫根據一系列百分位繪製直方圖?我一直在挖熊貓,但我沒有看到任何可用的方法。我知道一個很長的解決方法,那就是手動計算我想要的每個百分點的出現次數。但我認爲可能有更好的解決方案。按百分位數繪製直方圖

目前我必須讓個人計算

# Sample series 
tenth = df.col.quantile(0.1) 
twenty = df.col.quantile(0.2) 
twenty_count = len(twenty - tenth) 

等等......

然而,使用形容。我設法得到這個

df.describe(percentiles = [x/10.0 for x in range(1,11)] 
+0

鴻溝你能添加像'np.random.seed(10) DF = pd.DataFrame(np.random一些數據樣本。 randint(10,size =(20,1)),columns = ['col']) print(df)'帶有期望的輸出?或者如果有幫助,請接受anser。謝謝。 – jezrael

回答

2

IIUC

df.col.rank(pct=True).hist() 

然而,這是一個壞主意。

考慮下面的數據幀df

df = pd.DataFrame(dict(
     col=np.random.randn(1000), 
     col2=np.random.rand(1000) 
    )) 

然後

df.col.rank(pct=True).hist() 

enter image description here

這是一個愚蠢的曲線圖。

相反,由絕對值最大

(df/df.abs().max()).hist() 

enter image description here

+0

非常感謝 – aceminer