How to apply rolling functions in a group by object in pandas
问题 I'm having difficulty to solve a look-back or roll-over problem in dataframe or perhaps in groupby. The following is a simple example of the dataframe I have: fruit amount 20140101 apple 3 20140102 apple 5 20140102 orange 10 20140104 banana 2 20140104 apple 10 20140104 orange 4 20140105 orange 6 20140105 grape 1 … 20141231 apple 3 20141231 grape 2 I need to calculate the average value of 'amount' of each fruit in the previous 3 days for everyday, and create the following data frame: fruit