Modifying Code To Work For Month And Week Instead Of Year
I am making a stacked bar plot over a year time span where the x-axis is company names, y-axis is the number of calls, and the stacks are the months. I want to be able to make thi
Solution 1:
For days in a month ('2015-07' say) You could change
result = df.groupby([lambda idx: idx.month, 'CompanyName']).agg(len).reset_index()
to something like
month = '2015-07'result = df.loc[month].groupby([lambda idx: idx.day, 'CompanyName']).agg(len).reset_index()
And replace 'Month'
with 'Day'
below. You wouldn't have to bother with the OrderedDict etc. in this case as they are just ints. For a week you could do
start, end='2015-07-06', '2015-07-12'result= df.loc[start: end].groupby(
[lambda idx: idx.dayofweek, 'CompanyName']).agg(len).reset_index()
Post a Comment for "Modifying Code To Work For Month And Week Instead Of Year"