I can't understand the code:
pivot = pd.pivot_table(subset, values='count', rows=['date'], cols=['sample'], fill_value=0)
by = lambda x: lambda y: getattr(y, x)
grouped = pivot.groupby([by('year'),by('month')]).sum()
subset
in the code is a DataFrame which have a column named "date"(e.g.2013-02-04 06:20:49.634244), and do not have a column named "year" and "month".
where I have trouble with
I can't figure out the "year" and "month" in:
grouped = pivot.groupby([by('year'),by('month')]).sum()
What the meaning of
grouped = pivot.groupby([by('year'),by('month')]).sum()
What I have done:
In the pandas pandas document says: the first parame of the pandas.DataFrame.groupby can be
by : mapping function / list of functions, dict, Series, or tuple /
by = lambda x: lambda y: getattr(y, x)
means by('bar') returns a function that returns the attribute 'bar' from an object