I have pandas Series of DatetimeIndex in date format (YYYY-MM-DD
) and want to label consecutive regions, where each index is consecutive in respect to a day - so if there is a missing date in a Datetime series, I want to detect it, i.e.:
...
2005-01-15
2005-01-16
2005-01-17
2005-02-15
2005-02-16
...
where a gap of missing days between 2005-01-17 and 2005-02-15 is evident.
Couldn't find easy way to do this with pandas, while I expect some helper function that I'm not aware of. More generally, also numpy solution would be appreciated.
@smci, I don't know what dput()
is, but here is one way to generate sample data:
import pandas as pd
import numpy as np
data = pd.concat([
pd.Series(np.random.randn(3), pd.date_range('2005-01-15', '2005-01-17')),
pd.Series(np.random.randn(3), pd.date_range('2005-02-15', '2005-02-17'))
])