python时间数据合并_python – 使用numpy / pandas按时间戳合并时间序列数据

我想你可以简单

>将时间戳定义为每个DataFrame的索引(使用set_index)

>使用连接将它们与“外部”方法合并

> Optionnaly将时间戳转换为日期时间

这是它的样子.

# generating some test data

timestamp = [1440540000, 1450540000]

df1 = pd.DataFrame(

{'timestamp': timestamp, 'a': ['val_a', 'val2_a'], 'b': ['val_b', 'val2_b'], 'c': ['val_c', 'val2_c']})

# building a different index

timestamp = timestamp * np.random.randn(abs(1))

df2 = pd.DataFrame(

{'timestamp': timestamp, 'd': ['val_d', 'val2_d'], 'e': ['val_e', 'val2_e'], 'f': ['val_f', 'val2_f'],

'g': ['val_g', 'val2_g']}, index=index)

# keeping a value in common with the first index

timestamp = [1440540000, 1450560000]

你可能感兴趣的:(python时间数据合并)