Fix Python – Pandas aggregate count distinct

Let’s say I have a log of user activity and I want to generate a report of the total duration and the number of unique users per day.
import numpy as np
import pandas as pd
df = pd.DataFrame({‘date’: [‘2013-04-01′,’2013-04-01′,’2013-04-01′,’2013-04-02’, ‘2013-04-02’],
‘user_id’: [‘0001’, ‘0001’, ‘0002’, ‘0002’, ‘0002’],
‘duration’: [30, 15….

Fix Python – Multiple aggregations of the same column using pandas GroupBy.agg()

Is there a pandas built-in way to apply two different aggregating functions f1, f2 to the same column df[“returns”], without having to call agg() multiple times?
Example dataframe:
import pandas as pd
import datetime as dt
import numpy as np
df = pd.DataFrame({
“date” : [, x, 1) for x in range(1, 11)]….