i have a pandas dataframe with a column named period with 3 different labelling value which means winter 2019, winter 2020 and winter 2021 as shown below
my question is how do i replace this format with the end result being winter 2019, winter 2020 and winter 2021?
Period: Q4 '19+Q1 '20 Q4 '20+Q1 '21 Q4 '21+Q1 '22
Q means quarter in a year
So my approach is: 1) first is the regex method to make a new year column. I extract the '19, '20, '21 year number after the first Q4
gas['year'] = gas['Period'].str.extract("([']\d\d)", expand=True)
Then i plan to replace value containing Q4 and Q1 with winter by
gas['Period'].str.contains('Q4')) & (gas['Period'].str.contains('Q1')) = 'winter Gregorian'
but it replaced the whole row containing Q4 and Q1
gas[gas['Period'].str.replace("[Q]..\d\d[+][Q]", 'winter Gregorian'), regex =False]
and end result i would like something as:
Period winter Gregorian 2019 winter Gregorian 2020 winter Gregorian 2021
but didnt work, i welcome any advice and suggestions thanks