Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # flatten the groupby
- flat_week_groups = week_groups.reset_index()
- # create an index of all the weeks from start_date to now_date
- # to pick up the missing weeks
- dummy_index = []
- for dtime in rrule.rrule(rrule.WEEKLY, dtstart=start_date, until=now_date):
- dt_week = dtime.isocalendar()[1]
- dt_year = dtime.isocalendar()[0]
- dummy_index.append(tuple([dt_year, dt_week]))
- # add the missing weeks to flat_week_groups
- for i in dummy_index:
- if i not in week_groups.index:
- flat_week_groups = flat_week_groups.append( \\
- {'date_year': i[0], \\
- 'date_week': i[1], \\
- 'value': 0},ignore_index=True)
- # sort by year and week
- # re-stack the DataFrame with the added values for empty weeks
- week_groups = flat_week_groups.sort_values( \\
- ['date_year','date_week']).set_index(['date_year','date_week'])
- week_groups.plot(kind='bar',figsize=(10,5),legend=None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement