We need to return the list of dates for n consecutive business days ( Friday to Monday is 1 business day ). where values are not changed. Do not assume that dates column have every single dates. Data frame structure would be as given below
date Value
2022-07-19 44.43000000
2022-07-20 44.43000000
2022-07-21 44.43000000
2022-07-22 44.43000000
2022-07-25 44.43000000
... ...
2022-09-02 86.40000000
2022-09-06 85.13000000
2022-09-07 86.86000000
2022-09-08 88.44000000
2022-09-09 89.44000000
If we assume n is 5. We need to return list of 5 consecutive dates. For above examples answer would be
[2022-07-22,2022-07-20,2022-07-21,2022-07-22,2022-07-25]
I tried below code to get consecutive dates present in data frame but I am unable to get consecutive business days.
for k, v in px_dirty.groupby((px_dirty['value'].shift() != px_dirty['value']).cumsum()):
if len(v) == 5:
print(f'[group {k}]')
print(v)
I am not able to figure out how to get consecutive business days.