Jan-26-2024, 03:17 PM
I have a data structure that looks like so
Exemple :
1.1 would have a total of spent for all rows that begins with 1.1. (15)
1.2.1 and 1.2.1.0 would have a total of 12
I have done it without using pandas, but wondering if a simple method could be achieve with pandas.
Output: Cost Elements parent spent
1,1 2184AA None 0
1.1.1 2184DA 2184AA 0
1.1.1.0 2184A6 2184DA 0
1.1.1.0.1 8484XA 2184A6 10
1.1.1.0.2 8484YA 2184A6 5
1.2.1 2184BE 2184AA 0
1.2.1.0 2184B1 2184BE 0
1.2.1.0.1 8484B2 2184BE 4
1.2.1.0.2 8484B3 2184B1 8
What I am trying to achieve is create an extra column that would be a sum based on the hierarchy of the leftmost column. Exemple :
1.1 would have a total of spent for all rows that begins with 1.1. (15)
1.2.1 and 1.2.1.0 would have a total of 12
I have done it without using pandas, but wondering if a simple method could be achieve with pandas.