Creation of new column

Hello
I want to create a new column (D) that includes calculations from previous columns (A,B,C).
For reference image is provided below :-

Basically

first row is df[“D”] = df[“C”] + df[“A”] - df[“B”]

and rest of the rows are

df[“D”] = df[“C”] - df[“A”] + df[“B”]

How could I do that?

You’re using Pandas, right? Try Googling for “python pandas add column” or something similar.