I want to be able to get the average of the last 4 rows that are in 'Stage' 2, for each column.
Sample Data
Currently I am using av = df.loc[df['Stage'] == 2, 'Vout'].mean()
but this gives me the average for the entire column. So for the column vout I am getting the entire columns average value, when I just want the columns average value to be the average of the last 4 rows that are in stage 2.
Copyright Notice:Content Author:「fudgey」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70337244/getting-average-of-selected-rows-for-each-column-pandas