Skip to content

Tag: dataframe

Subtract rows in a grouped Dataframe

I have a pandas dataframe and i need to subtract rows if they have the same group. Input Dataframe: A B Value A1 B1 10.0 A1 B1 5.0 A1 B2 5.0 A2 B1 3.0 A2 B1 5.0 A2 B2 1.0 Expected Dataframe: A B Value A1 B1 5.0 A1 B2 5.0 A2 B1 -2.0 A2 B2 1.0 Logic: For example