How to calculate percent change compared to the beginning value using pandas?
问题 I have a DataFrame and need to calculate percent change compared to the beginning of the year by companies. Is there any way to use pct_change() or other method to perform this task? Thanks! df looks like security date price IBM 1/1/2016 100 IBM 1/2/2016 102 IBM 1/3/2016 108 AAPL 1/1/2016 1000 AAPL 1/2/2016 980 AAPL 1/3/2016 1050 AAPL 1/4/2016 1070 results I want security date price change IBM 1/1/2016 100 NA IBM 1/2/2016 102 2% IBM 1/3/2016 108 8% AAPL 1/1/2016 1000 NA AAPL 1/2/2016 980 -2%