基于python中的时间戳列连接两个数据帧

时间:2021-07-09 05:39:04

标签: python pandas

我有两个数据框。两者都具有相同的标题,因为它们是来自不同房屋的数据。我想根据时间戳列并排连接它们。以下是我正在使用的数据和代码示例。

df = pd.DataFrame()
for cluster in os.listdir():
    os.chdir(path +"\\"+ cluster)
    for H in os.listdir():
        os.chdir(path +"\\"+ cluster +"\\"+H )       
        for file in os.listdir():
            if file.endswith(".csv"):
                print(file)
                df1 = pd.read_csv(file)
                df1 = df1.set_index('Timestamp')
                df = pd.concat([df,df1], axis=1)
df.to_csv(path +"\\"+"mastersheet.csv")

我的数据框:

<头>
时间戳 能源 电压
12/02/2020 12:00:00 23 230
12/02/2020 12:15:00 23.5 234

等等。

我有来自不同房屋的类似表格,我想将它们与公共时间戳列并排放置。 使用我的代码,我收到以下错误:

Shape of passed values is (43395, 22), indices imply (32583, 22)

请帮忙

0 个答案:

没有答案