【发布时间】:2020-03-17 01:50:13
【问题描述】:
我是 python 新手,想要帮助合并两个 datafames:
a) 在数字字段 df1_UL_GTP_TEID_0_int 和 df2_TEID_UL_int 中应该具有相同的值
b) df1 START_TIME_roundoff 和 df2 TS_START_roundoff 之间的差异应该是 1 分钟。
df1
START_TIME_roundoff UL_GTP_TEID_0_int TIMSI/MSIN
46 2020-03-10 12:00:00 1196907781 3.240371e+09
190 2020-03-10 12:01:00 1147678181 3.244522e+09
308 2020-03-10 12:05:00 1147678181 3.244522e+09
496 2020-03-10 12:07:00 1691830165 3.252351e+09
632 2020-03-10 12:12:00 1809929829 3.237458e+09
df2
S_START_roundoff TEID_UL_int DIR
1 2020-10-03 09:59:00 1973380469 1
2 2020-10-03 10:00:00 2041336357 2
4 2020-10-03 12:06:00 1147678181 12
5 2020-10-03 09:57:00 1295205669 1
6 2020-10-03 12:12:00 1809929829 13
<<< Expected OUTPUT >>>
row 308 of df_1 should merge with row 4 of df_2
and row 632 of df_1 should merge with row 6 of df_2
逻辑:
If absolute value of |df1.START_TIME_roundoff - df2.TS_START_roundoff| <= 1 then
df_new = pd.merge(df_1, df_2, how='inner', left_on='UL_GTP_TEID_0_int', right_on='TEID_UL_int')
提前致谢,
【问题讨论】:
-
请提供一个可供人们使用的复制/粘贴数据框。
-
已添加。这是你要求的吗?
标签: python pandas dataframe merge