I have this dataframe (ID is a string and Value a float):
ID Value
1 0.0
1.1 0.0
1.2 0.0
1.2.1 27508.42
1.2.2 25861.82
1.3 0.0
1.3.1 0.0
1.3.1.1 0.0
1.3.1.2 0.0
1.3.1.3 30396.25
Whose structure works like this:
1
├── 1.1
├── 1.2
│ ├── 1.2.1
│ └── 1.2.2
└── 1.3
└── 1.3.1
├── 1.3.1.1
├── 1.3.1.2
└── 1.3.1.3
And need for the value of the 'parent' node to be the sum of the leaves. So:
ID Value
1 83766.489 (1.1 + 1.2 + 1.3)
1.1 0.0
1.2 53370.24 (1.2.1 + 1.2.2)
1.2.1 27508.42
1.2.2 25861.82
1.3 30396.25 (1.3.1)
1.3.1 30396.25 (1.3.1.1 + 1.3.1.2 + 1.3.1.3)
1.3.1.1 0.0
1.3.1.2 0.0
1.3.1.3 30396.25
How can I group the IDs? Using groupby wont work since all the IDs are unique. Should I change the structure of the dataframe to better reflect the logic of the schema?