Marking certain days in date indexed pandas dataframes
<p>I've got a dataframe which is date indexed (d-m-y). I wanted to create a binary feature column which denotes if a date is the second Saturday of the month.<br>
What I've got so far is this:  </p>

<pre><code>def get_second_true(x):
    second = None
    for index, is_true in enumerate(x):
        if is_true and second is None:
            return index
        if is_true and second is not None:
            second = True

second_saturdays = df.groupby(['month', 'year']).apply(
    lambda x: x.index.weekday == 6
    ).apply(get_second_true)
</code></pre>

<p>I'm unable to get this back into a series which relates to the original dataframe's index in such a way that each row has a label of whether it is a second Saturday or not.</p>

<p>This feels like a common enough scenario, but I am unable to find the term used for doing such a thing. I've looked at <code>unstack</code> and <code>reset_index</code> but I don't understand them in enough depth to know if this can be done using them, or if multilevel indexing is even needed at all.</p>

<p>The day is second Saturday of the month if weekday == 6 and day of the moth > 7 and day of the month &lt;= 14</p>

python pandas dataframe