I am trying to determine a more efficient to add specific values in a pandas df.
For the df below, I want to add the integers in Value for each X + Y in Area. So, for every X, I want to add that to the following Y.
import pandas as pd
d = ({
'Area' : ['X','Y','Z','X','Y','Z'],
'Value' : [10,11,20,21,30,31],
})
df = pd.DataFrame(data=d)
If there's not many values I can go through manually as per the following:
x = df.iloc[0] + df.iloc[1]
But if the df is quite large, this becomes inefficient.
Intended Output:
21
51