I'm trying to create new lines between the start_date and end_date, based on a certain ID. My dataframe looks like this:
id start_date end_date
0 477 2020-02 2020-04
1 518 2020-08 2020-08
2 553 2020-03 2020-04
3 925 2020-07 2020-09
4 948 2020-05 2020-06
5 971 2020-02 2020-07
6 987 2020-01 2020-02
7 117 2020-06 2020-07
8 117 2020-05 2020-07
9 133 2020-05 2020-06
For example. If the ID 477 (first one) begins in 2020-02 and ends in 2020-04, i have to create a new dataframe with plus two new lines, like this:
id dates
0 477 2020-02
1 477 2020-03
2 477 2020-04
3 553 2020-03
4 553 2020-04
In the end, i'm trying to create a pivot with the following code and structure:
pd.pivot_table(columns=df_churn['end_date'], index=df_churn['id'], aggfunc='count', data=df_churn, fill_value=0)
This is what the table would look like:
2020-02 2020-03 2020-04 2020-05 2020-06 2020-07 2020-08 2020-09 2020-10
id
477 1 1 1 0 0 0 0 0 0
518 0 0 0 0 0 0 1 0 0
553 0 1 1 0 0 0 0 0 0