I have a pandas dataframe that looks something like this:
user date value
1 01-2000 5
1 02-2000 6
1 03-2000 7
1 04-2000 8
2 01-2000 3
2 02-2000 4
2 03-2000 5
2 04-2000 6
3 01-2000 10
3 02-2000 11
3 03-2000 12
3 04-2000 13
I'd like to create a new column with the value for each user for the previous month, so it looks something like this:
user date value new_col
1 01-2000 5 NaN
1 02-2000 6 5
1 03-2000 7 6
1 04-2000 8 7
2 01-2000 3 NaN
2 02-2000 4 3
2 03-2000 5 4
2 04-2000 6 5
3 01-2000 10 NaN
3 02-2000 11 10
3 03-2000 12 11
3 04-2000 13 12
Please can someone advise how best to do this? Thanks.