Create Period column based on a date column where the first month is 1, second 2, etc
I have a dataset with many project's monthly expendituries (cost curve), like this one:
Project | Date | Expenditure(USD) |
---|---|---|
Project A | 12-2020 | 500 |
Project A | 01-2021 | 1257 |
Project A | 02-2021 | 125889 |
Project A | 03-2021 | 102447 |
Project A | 04-2021 | 1248 |
Project A | 05-2021 | 1222 |
Project A | 06-2021 | 856 |
Project B | 01-2021 | 5589 |
Project B | 02-2021 | 52874 |
Project B | 03-2021 | 5698745 |
Project B | 04-2021 | 2031487 |
Project B | 05-2021 | 2359874 |
Project B | 06-2021 | 25413 |
Project B | 07-2021 | 2014 |
Project B | 08-2021 | 2569 |
Using python, I want to create a Period column that replace the month value for a integer that represents the count of months of the project, like this: Where the line is the first month of the Project A (12-2020) the code should put 1 in the Period column, the second month (01-2021) is 2, the third (02-2021) is 3, etc. because I need to focus on the number of months that the projects of my dataframe had an expediture (month 1, month 2, month 3...)
Project | Date | Period | Expenditure(USD) |
---|---|---|---|
Project A | 12-2020 | 1 | 500 |
Project A | 01-2021 | 2 | 1257 |
Project A | 02-2021 | 3 | 125889 |
Project A | 03-2021 | 4 | 102447 |
Project A | 04-2021 | 5 | 1248 |
Project A | 05-2021 | 6 | 1222 |
Project A | 06-2021 | 7 | 856 |
Project B | 01-2021 | 1 | 5589 |
Project B | 02-2021 | 2 | 52874 |
Project B | 03-2021 | 3 | 5698745 |
Project B | 04-2021 | 4 | 2031487 |
Project B | 05-2021 | 5 | 2359874 |
Project B | 06-2021 | 6 | 25413 |
Project B | 07-2021 | 7 | 2014 |
Project B | 08-2021 | 8 | 2569 |
Topic project-planning data-science-model python-3.x scipy dataset
Category Data Science