pandas generate a sequence of dates according to a pattern

I have this sequence of dates and I want to create a column with a flag according to a 3-2 pattern: 3 days in a row flagged, then 2 days not flagged etc.

import pandas as pd
date_pattern = pd.date_range(start='2020-01-01', end='2020-06-30')
date_pattern = pd.DataFrame({"my_date": date_pattern})
date_pattern

wanted a ‘flag’ column, having for instance 1 for the range 01 to 03 jan, then from 06 to 08 jan, etc.

Answer

You can use modulo 5 with index values and then compare for less like 3 for each fourth and fifth row:

date_pattern['flag'] = date_pattern.index % 5 < 3
#alternative for not default index
#date_pattern['flag'] = np.arange(len(date_pattern)) % 5 < 3
print(date_pattern.head(15))
      my_date   flag
0  2020-01-01   True
1  2020-01-02   True
2  2020-01-03   True
3  2020-01-04  False
4  2020-01-05  False
5  2020-01-06   True
6  2020-01-07   True
7  2020-01-08   True
8  2020-01-09  False
9  2020-01-10  False
10 2020-01-11   True
11 2020-01-12   True
12 2020-01-13   True
13 2020-01-14  False
14 2020-01-15  False