Python Forum
Add a row per group and depending of values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add a row per group and depending of values
#1
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 !

Attached Files

Thumbnail(s)
       
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 220 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  conditional groupby and aggregation on the conditioned group values harrshu 1 1,992 Oct-20-2019, 10:24 AM
Last Post: DeaD_EyE
  executing a line depending on the input PierreSoulier 4 2,968 Jul-17-2018, 02:39 PM
Last Post: PierreSoulier

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020