Pandas how to get rows with consecutive dates and sales more than 1000?
You can assign a unique identifier per consecutive days, group by them, and return the first value per group (with a previous filter of values > 1000):
df = df.query('Sales > 1000').copy()
df['grp_date'] = df.Date.diff().dt.days.fillna(1).ne(1).cumsum()
df.groupby('grp_date').head(7).reset_index(drop=True)
where you can change the value of head
parameter to the first n
rows from consecutive days.
Note: you may need to use pd.to_datetime(df.Date, format='%d/%m/%Y')
to convert dates from strings to pandas datetime, and sort them.