I'm still quite new to Python, and after looking intensively here on SO, I've decided to just ask.
I have a DataFrame, df
df
NO2 NO2 NO3 DK1 DK2
0 1.0 3.0 2.0 1.0 1.0
1 1.0 3.0 3.0 3.0 1.0
2 2.0 2.0 2.0 1.0 1.0
Now, what I want to do is sum up all values in row 0 that are equal to the value in column "DK1" (incl. itself) and return it in a new column. Then after doing that for row 0, the same procedure for row 1, then row 2, etc.
Desired output:
df2
NO2 NO2 NO3 DK1 DK2 Sum
0 1.0 3.0 2.0 1.0 1.0 3.0
1 1.0 3.0 3.0 3.0 1.0 9.0
2 2.0 2.0 2.0 1.0 1.0 2.0