python - Pandas: Group by Time, then plot density per group -


i'm trying group data frame time , plot density of variable each subgroup. i'm doing:

mydf.groupby(pd.timegrouper('as'))['myvar'].plot(kind='density') 

here's result:

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 

and plot:

output

how add correct legend plot? there's no way know line corresponds year right now.

set legend argument true:

mydf.groupby(pd.timegrouper('as'))['myvar'].plot(kind='density', legend=true) 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -