手上 3 个数据流的开始时间不一致,所以需要对齐数据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import pandas as pd
filepath1 = '' filepath2 = '' """ date d1 2022/5/24 2350 2022/5/25 2340 2022/5/26 2340 2022/5/27 2325
date d2 2022/5/26 2590 2022/5/27 2590 2022/5/30 2590 2022/5/31 2580 """
df1 = pd.read_csv(filepath1) df2 = pd.read_csv(filepath2) data = pd.merge(df1, df2, on='date', how='outer') print(data)
""" date d1 d2 0 2022-05-24 2350.0 NaN 1 2022-05-25 2340.0 NaN 2 2022-05-26 2340.0 2590.0 3 2022-05-27 2325.0 2590.0 4 2022-05-30 NaN 2590.0 5 2022-05-31 NaN 2580.0 """
|