I have a DataFrame like this
df = pd.DataFrame({
'comments': {0: 0, 1: 1, 2: 47, 3: 102, 4: 230},
'content_len': {0: 4305, 1: 7344, 2: 8431, 3: 5662, 4: 3706},
'day': {0: 1, 1: 1, 2: 1, 3: 2, 4: 2},
'dayofweek': {0: 2, 1: 2, 2: 2, 3: 3, 4: 3},
'domain': {0: 'habrahabr.ru',
1: 'habrahabr.ru',
2: 'habrahabr.ru',
3: 'habrahabr.ru',
4: 'geektimes.ru'},
'favs': {0: 0, 1: 1, 2: 72, 3: 36, 4: 6},
'post_id': {0: 18284, 1: 18285, 2: 18286, 3: 18291, 4: 18294},
'views': {0: 236, 1: 353, 2: 1200, 3: 5700, 4: 1400},
'votes_minus': {0: 0.0, 1: 0.0, 2: 5.0, 3: 3.0, 4: 15.0},
'votes_plus': {0: 0.0, 1: 1.0, 2: 45.0, 3: 72.0, 4: 73.0},
'year_month': {0: datetime.strptime('2008-01-01', '%Y-%m-%d'),
1: datetime.strptime('2008-01-01', '%Y-%m-%d'),
2: datetime.strptime('2008-02-01', '%Y-%m-%d'),
3: datetime.strptime('2008-02-01', '%Y-%m-%d'),
4: datetime.strptime('2008-03-01', '%Y-%m-%d'),}})
Now I want to plot different graphics grouped by 'year_month', one graphic per domain.
For example number of articles
df[df.domain=='habrahabr.ru'].groupby('year_month').count()[['domain']].rename(columns={'domain':'habrahabr.ru'}).join(
df[df.domain=='geektimes.ru'].groupby('year_month').count()[['domain']].rename(columns={'domain':'geektimes.ru'})).plot()
or mean content_len
df[df.domain == 'habrahabr.ru'].groupby('year_month').mean()[['content_len']].rename(columns={'content_len':'habrahabr.ru'}).astype(int).join(
df[df.domain == 'geektimes.ru'].groupby('year_month').mean()[['content_len']].rename(columns={'content_len':'geektimes.ru'}).astype(int)).plot()
Is there a more elegant solution than the one I've given?