Count rows with consecutive dates within PANDAS groupby
<p><a href="https://stackoverflow.com/questions/38753823/how-to-identify-consecutive-dates">This is the closest to what i'm looking for that I've found</a></p>

<p>Let's say my dataframe looks something like this: </p>

<pre><code>d = {'item_number':['K208UL','AKD098008','DF900A','K208UL','AKD098008']
     'Comp_ID':['998798098','988797387','12398787','998798098','988797387']
     'date':['2016-11-12','2016-11-13','2016-11-17','2016-11-13','2016-11-14']}

df = pd.DataFrame(data=d)
</code></pre>

<p>I would like to count the amount of times where the same <code>item_number</code> and <code>Comp_ID</code> were observed on consecutive days. </p>

<p>I imagine this will look something along the lines of:</p>

<pre><code>g = df.groupby(['Comp_ID','item_number'])
g.apply(lambda x: x.loc[x.iloc[i,'date'].shift(-1) - x.iloc[i,'date'] == 1].count())
</code></pre>

<p>However, I would need to extract the day from each date as an int before comparing, which I'm also having trouble with. </p>

<pre><code>for i in df.index:
    wbc_seven.iloc[i, 'day_column'] = datetime.datetime.strptime(df.iloc[i,'date'],'%Y-%m-%d').day
</code></pre>

<p>Apparently location based indexing only allows for integers? How could I solve this problem?</p>