Skip to content
Advertisement

Add new column with specific increasing of a quarter using python

I have a dataframe, df, that has a quarters column where I would like to add an additional increased quarters column adjacent to it (increased by 2)

Data

JavaScript

Desired

JavaScript

Doing

JavaScript

However this is not adding 2 consistently to the entire column I am still troubleshooting, any suggestion is appreciated

Advertisement

Answer

Reformat the strings in date in such a way that the resulting date format is YearQuarter so that it can be parsed into PeriodIndex, now add 2 to this index and strftime to convert back to orignal format

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement