I think that I was a little too slow in removing the word 'simple' from the offer of making it dynamic, the formula is much the same as the one in my last reply but you won't need to edit it if you add more data to the source, just fill down as needed.
Whilst the formula looks more complicated, it uses simpler and more efficient methods to process the data. You may, or may not notice a difference in calculation time for the formula when compare to one using averageifs depending on a number of factors.
One thing that I should point out is that all of the suggestions provided assume that (for example) all Apples will be in consecutive rows, if they are separated then each group of Apples will have its own average.
Excel Formula:
=IF(B3=B4,"",LET(l,MATCH("zzz",B:B),r,C$2:INDEX(C:C,l),AVERAGE(C3:INDEX(r,IFERROR(MATCH(1E+100,D$2:D2)+1,1)))))
B3=B4 should refer to the item of interest (e.g. Apples) in the same row as the formula, and the row below.
B:B should refer to the entire column of items.
C$2 should refer to the cell immediately above the first value in the column of values to average.
C:C should refer to the entire column of values.
C3 should refer to the value cell in the same row as the formula.
D$2:D2 should refer to the cell above the one where you enter the first formula before filling down.
Hopefully that all makes sense.