I have the following DataFrame. For each row, I want the average purchase price for the user prior to that purchase. How should the code be written?
userid product price website date
0 123 xt23 20 Amazon 2018-01-12
1 123 q45 2 Amazon 2018-01-08
2 123 a89 25 NewEgg 2018-01-06
3 77 q45 3 NewEgg 2018-01-03
4 77 a89 30 NewEgg 2018-01-05
5 92 xt23 24 Amazon 2018-01-04
6 92 m33 60 Amazon 2018-01-07
7 92 a89 28 Amazon 2018-01-02