Reputation: 43
I have a pandas datetime column where dates are not sorted. I want to select all the dates for which the next 6 consecutive dates are available in the column without any missing day in between.
My data looks something like this and I have marked the date I want in the image.
Upvotes: 1
Views: 162
Reputation: 712
Try this:
import pandas as pd
from datetime import timedelta
df = pd.read_excel(r'C:\Users\me\Desktop\Sovrflw_data.xlsx')
df
df.sort_values(by='dates', inplace=True)
df[df['dates'] - df['dates'].shift(-6) == timedelta(-6)]
df.sort_index(inplace=True)
Upvotes: 2