'Resample grouped data in Python
I asked a similar question before but I am trying to resample a dataframe with tick data to minute data such that the beginning and ending of the resulting time series encompasses the beginning of the day of the earliest time stamp and the end of the day of the last time stamp. I have some sample code below:
df = pd.DataFrame(data={'Code': pd.Series(['A', 'A', 'B', 'B'], dtype='str'),
'Timestamp': pd.Series([1608627600073933, 1698929600124359, 1608627600073933, 1608929600124359], dtype='datetime64[ns]'),
'Val':[5, 6, 5, 6]})
df.set_index(['Timestamp'], inplace=True)
df.groupby('Code').resample('1T').agg('sum')
The above code creates a dataframe that starts and ends with the first and last available tick data, but I would like it to begin and end at their respective points of the day.
It also ignores the grouping of the data by code and just gives a single time series with out codes.
The resulting dataframe should have 5760 rows since it encompasses 1440 minutes over 2 days for 2 codes. (1440 x 2 x 2)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
