I have a multi-indexed DataFrame and I need to insert a new column that has the same amount of data as level 0 index.
The details and an example: 1-There is one period element per patient. 2-Each patient has a variable amount of notes, so I can't repeat fixed n_times each period element. 3-I need all the data in the same data frame.
I hope the example adds enough clarity
patient note_number info
1 1 bla
1 2 bla
1 3 bla
2 4 bla
2 5 bla
3 6 bla
3 7 bla
period (each for one particular patient)
5 days
3 days
11 days
I have this multiindexed dataframe:
patient note_number info
1 1 bla
2 bla
3 bla
2 4 bla
5 bla
3 6 bla
7 bla
I need something like:
patient period note_number info
1 5 days 1 bla
2 bla
3 bla
2 3 days 4 bla
5 bla
3 11 days 6 bla
7 bla
How can I accomplish something similar? Correspondance is needed. First period element has to be paired with first patient and so on. Thanks