'Create a new columns to show the month of last spend in Pandas

I am working on a spend data where I want to see the last month when the spend was made in current and previous year. If there is no spend in these years, then, I assume the last month of spend as Dec-2020.

My data looks like this

enter image description here

As shown in the data the months are already there in the form of columns. I want to create a new column last_txn_month which gives last month when the spend was made. So the output should look like this:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source