I have a pandas dataframe with sorting on column 'DT' like this:
S DT
100 2000-12-12 05:00:00
100 2000-12-12 05:00:50
89 2000-12-12 05:01:20
89 2000-12-12 05:02:00
89 2000-12-12 05:02:35
98 2000-12-12 05:03:15
98 2000-12-12 05:03:50
98 2000-12-12 05:04:28
98 2000-12-12 05:05:05
112 2000-12-12 05:05:47
112 2000-12-12 05:06:15
112 2000-12-12 05:07:00
How can I find the previous of any given value in column 'S' from this data?
Like for S = 112, its previous should give 98, for 98 it should give prev = 89 and so on. I would like to store the previous values for any given 'S' in a separate variable which I can later access in my code. Any help will be deeply appreciated as I am new to the world of coding.