I wish to group and to convert datetimes to quarters within my dataset, df.
Data
location start end
aa/bb 1/1/2022 2/1/2022
aa/bb 2/1/2022 3/1/2022
aa/bb 3/1/2022 4/1/2022
cc/dd 4/1/2022 5/1/2022
cc/dd 5/1/2022 6/1/2022
cc/dd 6/1/2022 7/1/2022
Desired
location start end
aa/bb Q1 22 Q1 22
cc/dd Q2 22 Q2 22
Doing
df['start'] = pd.to_datetime(df['start'])
df['end'] = pd.to_datetime(df['end'])
df['start'] = pd.PeriodIndex(df['start'], freq='Q').strftime('Q%q.%y')
df['end'] = pd.PeriodIndex(df['end'], freq='Q').strftime('Q%q.%y')