1>>>print(df)2 time character
3100:02:56 Cobb
4200:03:22 Saito
5300:05:12 Saito
6400:05:50 Mal
7500:06:03 Arthur
8600:06:37 Mal
9700:08:21 Cobb
10800:08:41 Mal
11>>>12>>>import datetime
13>>>14>>> now = datetime.datetime.now()15>>> today = datetime.datetime.combine(now, datetime.time(0))16>>> df['time']= df['time'].apply(lambda x: datetime.datetime.combine(now, x)- today)17>>>18>>>defnear(df, i, distance = datetime.timedelta(seconds=60)):19... df_result = df[df['time']-df.iloc[i]['time']<=distance].iloc[i+1:]20... df_result['base_time']= df.iloc[i]['time']21... df_result['base_character']= df.iloc[i]['character']22...return df_result
23...24>>> df_near = pd.concat([near(df, i)for i inrange(len(df))])25>>>26>>> df_near['near_character']= df_near['base_character']+'-'+ df_near['character']27>>>28>>>print(df_near)29 time character base_time base_character near_character
3020 days 00:03:22 Saito 0 days 00:02:56 Cobb Cobb-Saito
3140 days 00:05:50 Mal 0 days 00:05:12 Saito Saito-Mal
3250 days 00:06:03 Arthur 0 days 00:05:12 Saito Saito-Arthur
3350 days 00:06:03 Arthur 0 days 00:05:50 Mal Mal-Arthur
3460 days 00:06:37 Mal 0 days 00:05:50 Mal Mal-Mal
3560 days 00:06:37 Mal 0 days 00:06:03 Arthur Arthur-Mal
3680 days 00:08:41 Mal 0 days 00:08:21 Cobb Cobb-Mal