IntervalIndex的
IntervalIndex.from_arrays第一:
s = pd.IntervalIndex.from_arrays(df2['start'], df2['stop'], 'both')print (s)IntervalIndex([[2016-08-31 08:09:00, 2016-08-31 08:12:00], [2016-08-31 08:13:00, 2016-08-31 08:20:00], [2016-08-31 08:20:00, 2016-08-31 08:45:00]], closed='both', dtype='interval[datetime64[ns]]')
然后
set_index通过新
IntervalIndex设置将新列按以下条件创建的数组
values:
df1['C'] = df2.set_index(s).loc[df1.index, 'C'].valuesprint (df1) A C2016-08-31 08:09:00 1.0 a2016-08-31 08:11:00 7.0 a2016-08-31 08:14:00 90.0 b
编辑:
s = pd.IntervalIndex.from_arrays(df2['start'].astype(np.int64), df2['stop'].astype(np.int64), 'both')print (s)IntervalIndex([[1472630940000000000, 1472631120000000000], [1472631180000000000, 1472631600000000000], [1472631600000000000, 1472633100000000000]], closed='both', dtype='interval[int64]')df1['C'] = df2.set_index(s).loc[df1.index.astype(np.int64), 'C'].valuesprint (df1) A C2016-08-31 08:09:00 1.0 a2016-08-31 08:11:00 7.0 a2016-08-31 08:14:00 90.0 b
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)