2015-03-31 61 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) 
中的情节通话