I would like to select specific days in a table to calculate the mean for each specific group. My table has around 9000 lines like these: Example Data
I would like to select only one value for every -first value of a month, -last value of a month, -second value of a month, -every 15th, -the day before the 15th, -the day after 15th
The purpose is to calculate the mean for every specific group.
The result should look like this: Result
I am struggeling with the calculation for the 15th/before/after as well as "after the first".
What I tried so far is:
import pandas as pd
df = pd.read_csv
df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)
"Average first of month"
dffirst = df[~df.index.to_period('m').duplicated()]
monthly_first = dffirst['Value'].mean()
"Average last of month"
dflast = df.resample("M").max()
monthly_last = dflast['Value'].mean()
Thank you