Dividing Pandas Dataframe by Week
<p>I have a dataframe with columns "Date" and "Num". </p>

<pre><code>dates = pd.date_range('1/1/2001','1/1/2003', freq = 'd')
nums = [np.random.randint(100) for x in range(len(dates))]

df = pd.DataFrame({'Dates': dates, 'DOW': dates.strftime('%a'), 'Nums': nums})
df = df[(df.DOW != 'Sat') &amp; (df.DOW !='Sun')]
df = df.drop([7,18]).reset_index(drop = True)
</code></pre>

<p>I need to bin the dataframe so I can isolate each week separately. The ultimate goal is to look at the MAX 'Nums' value for each week and compare it to the LAST value of the following week to see what the percent change is. For example:</p>

<pre><code>week1 = df[0:5]
week2 = df[5:9]
week3 = df[9:12]

In [156]: w1max = week1.Nums.max()
Out[156]: 97

In [157]: w2Last = week2.iloc[-1].Nums
Out[157]: 76

pctChange = (w2Last-w1max)/float(w1max)

In [166]: pctChange
Out[166]: -0.21649484536082475
</code></pre>

<p>The problem is that some weeks are missing days (eg week2 is missing monday and week3 is missing friday). So how do I separate them out?</p>

<p>The closest thing seems to be using <code>df.resample()</code> but I don't know how to make the comparison I'm trying to make using that.</p>