I have a dataframe (df) with 2 columns and 1 index.
Index is datetime index and is in format of 2001-01-30 .... etc and the index is ordered by DATE and there are thousands of identical dates (and is monthly dates). Column A is company name (which corresponds to the date), Column B are share prices for the company names in column A for the date in the Index.
Now there are multiple companies in Column A for each date, and companies do vary over time (so the data is not predictable fully).
I want to create a Column C which lags all the prices which are in B forward to the next date (as per in the index).
A basic .shift() would not work, as I would require all the prices to be shifted based on the condition that the company is still there at the next point in the index.
I want a column C which shifts B forward by 1, and a column D which shifts it back by 1.
I have been stuck on this for a while, somebody very smart please help.
Thanks