Select Rows Per Groups And With Time Conditions
A B C 0 2002-01-16 2002-02-28 HH 1 2002-01-16 2002-01-30 DX 2 2002-01-16 2002-02-28 TY 3 2002-01-16 2002-01-30 FY 4 2002-04-28 2002-04-30 PE 5 2002-04-28
Solution 1:
Let's try:
df[df['Diff'] == df['A'].map(df[df.Diff > pd.Timedelta('2 days')]
.groupby('A')['Diff'].min())]
Output:
ABCDiff12002-01-16 2002-01-30 DX14days32002-01-16 2002-01-30 FY14days52002-04-28 2002-05-25 CO27days72002-04-28 2002-05-25 DS27days
Post a Comment for "Select Rows Per Groups And With Time Conditions"