2015-03-31 48 views
1

我試圖按時間分組數據幀,然後繪製每個子組的變量密度。我做:熊貓:按時間分組,然後每組密度

myDf.groupby(pd.TimeGrouper('AS'))['myVar'].plot(kind='density') 

這裏的結果:

date 
2006-01-01 Axes(0.125,0.1;0.775x0.8) 
2007-01-01 Axes(0.125,0.1;0.775x0.8) 
2008-01-01 Axes(0.125,0.1;0.775x0.8) 
2009-01-01 Axes(0.125,0.1;0.775x0.8) 
2010-01-01 Axes(0.125,0.1;0.775x0.8) 
Name: myVar, dtype: object 

和劇情:

output

如何正確傳說添加到情節?沒有辦法知道哪一行對應於哪一年。

+1

,加kwarg:'標籤= pd.TimeGrouper( 'AS')) '日期']'(或類似的東西,拿到日期值),然後調用'legend'。 – cphlewis 2015-04-01 00:12:41

回答

0

設置legend參數True

myDf.groupby(pd.TimeGrouper('AS'))['myVar'].plot(kind='density', legend=True) 
中的情節通話