I have a data frame of the form:
df = [["john","2019","30.2"] , ["john","2019","40"] , ["john","2020","50.3"] ,
["amy","2019","60"] , ["amy","2019","20"] , ["amy","2020","40.1"]]
my desired result would be a list of multi-conditional summations of the last index while the first two are equal:
> [["john", "2019", "70.2"] , ["john","2020","50.3"] , ["amy","2019","80"] , ["amy","2020","40.1"]]
What I tried to do, was a for loop that checks equality for each condition and then sums up the last index, if conditions are true – this is some kind of a pseudo-code:
for i in df[i]:
if df[i][0] == df[i+1][0] and df[i][1] == df[i+1][1]: #if both conditions are true
sum1 = sum(float(df[i][2]))
lst = []
lst.append(df[i][0])
lst.append(df[i][1])
lst.append(str(sum1))
Edit: Would appreciate a solution that doesn't use packages.