Python Forum

Full Version: Add a row per group and depending of values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I have this dataframe (see capture 1).

And I 'd like to add one row per group of the Var_1 such as I have a new value Var_2=3. And the value in var_4 would be equal to (Var_5 value of the group - sum of the values of the Var_4).
So i would end up with the df in capture 2.

I'm not sure if this is clear but the capture 2 will give you a good idea of what I m looking for. And I'd like to automate this for each Var_1 group (so i'd like not to enter the raw values "A", "B" and "C" in the code).

I thank you very much by advance for your help !