Pandas number of unique users grouped by year-week
<p>I have a report_date column that I want to aggregate by its year-week and count the number of unique users.</p>

<pre><code>import pandas as pd
from io import StringIO

datastring = StringIO("""\
report_date  user_id
2015-12-01         1
2015-12-01         2
2015-12-01         2
2015-12-02         2
2015-12-02         3
2016-01-01         1
""")

df = pd.read_table(datastring, sep='\s\s+', engine='python')
df['report_date'] = pd.to_datetime(df['report_date'])
</code></pre>

<p>Output I want:</p>

<pre><code>2015-48    3
2016-00    1
</code></pre>

<p>I have come up with a solution (posted below) but it's relatively slow when using a much larger dataset (> 1MM rows). Curious if there's a better solution to this problem.</p>