I have the following DataFrame. I am wondering whether it is possible to break the data
column into multiple columns. E.g., from this:
ID Date data 6 21/05/2016 A: 7, B: 8, C: 5, D: 5, A: 8 6 21/01/2014 B: 5, C: 5, D: 7 6 02/04/2013 A: 4, D:7 7 05/06/2014 C: 25 7 12/08/2014 D: 20 8 18/04/2012 A: 2, B: 3, C: 3, E: 5, B: 4 8 21/03/2012 F: 6, B: 4, F: 5, D: 6, B: 4
into this:
ID Date data A B C D E F 6 21/05/2016 A: 7, B: 8, C: 5, D: 5, A: 8 15 8 5 5 0 0 6 21/01/2014 B: 5, C: 5, D: 7 0 5 5 7 0 0 6 02/04/2013 B: 4, D: 7, B: 6 0 10 0 7 0 0 7 05/06/2014 C: 25 0 0 25 0 0 0 7 12/08/2014 D: 20 0 0 0 20 0 0 8 18/04/2012 A: 2, B: 3, C: 3, E: 5, B: 4 2 7 3 0 5 0 8 21/03/2012 F: 6, B: 4, F: 5, D: 6, B: 4 0 8 0 6 0 11
I have tried this Split strings in tuples into columns, in Pandas, and this pandas: How do I split text in a column into multiple rows? but they are not working in my case.
EDIT
There is a bit of complexity the data
column has duplicate values for example in first row A
is repeated, and therefore these values are summed up under the A
column (please see second table).