Reputation: 397
I have a dataframe in pandas that looks similar to this:
ApplicationId | Application Date | Account
1234 | 10/01/2018 | 12345
5678 | 10/30/2018 | 12345
9101 | 11/15/2018 | 12345
1213 | 10/01/2018 | 67891
1415 | 11/01/2018 | 67891
1617 | 10/01/2018 | 43210
I need to join the dataframe with itself to get the "next application date" based on Account and Application Date. SO the final result should be:
ApplicationId | Application Date | Account | Next Application Date
1234 | 10/01/2018 | 12345 | 10/30/2018
5678 | 10/30/2018 | 12345 | 11/15/2018
9101 | 11/15/2018 | 12345 | Nan
1213 | 10/01/2018 | 67891 | 11/01/2018
1415 | 11/01/2018 | 67891 | Nan
1617 | 10/01/2018 | 43210 | Nan
Could you please advise?
Thank you!
Upvotes: 0
Views: 228
Reputation: 323306
I think this is groupby
+ shift
problem
df['New']=df.groupby('Account')['Application Date'].shift(-1)
Upvotes: 5