pandas:附条件的数据框

pandas:附条件的数据框,第1张

pandas:附条件数据

请尝试以下 *** 作

# Transform data in first dataframedf1 = pd.Dataframe(data)# Save the data in another datframedf2 = pd.Dataframe(data)# Rename column names of second dataframe df2.rename(index=str, columns={'Reader_ID1': 'Reader_ID1_x', 'SITE_ID1': 'SITE_ID1_x', 'EVENT_TS1': 'EVENT_TS1_x'}, inplace=True)# Merge the dataframes into another dataframe based on PERSonID and Badge_IDdf3 = pd.merge(df1, df2, how='outer', on=['PERSONID', 'Badge_ID'])# Use df.loc() to fetch the data you wantdf3.loc[(df3.Reader_ID1 < df3.Reader_ID1_x) & (df3.SITE_ID1 != df3.SITE_ID1_x) & (pd.to_datetime(df3['EVENT_TS1']) - pd.to_datetime(df3['EVENT_TS1_x'])<=datetime.timedelta(hours=event_time_diff))]


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5617245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存