如何加入相同时间戳的行?

How to join rows of same timestamp?

我有两个 pandas 带有时间戳和值列的数据帧,如下所示:

                  timestamp            value1
0    2015-01-01T15:41:10.500Z    9239.337890625
1    2015-01-01T15:41:50.543Z    9539.337890625
2    2015-01-01T15:42:30.600Z    8957.0458984375
3    2015-01-01T15:43:00.606Z    8237.0458984375

我尝试使用 pandas.concat

组合它们
df_all = pd.concat([df1, df2, df3, ...], ignore_index = True)
df_all.sort_values(by='timestamp', inplace = True)

它做了我想要的,但结果包含如下值:

     value1      value2  timestamp
 133 9587.165039 NaN     2015-01-18T00:00:00.000Z 
 0   NaN         0.14    2015-01-18T00:00:00.000Z

具有相同的时间戳。如何加入这些行,使它们成为:

 value1      value2  timestamp
 9587.165039 0.14    2015-01-18T00:00:00.000Z 

非常感谢任何建议或评论。

concat 不会填补空白。你需要在你的 DataFrame 上做 merge。 要合并多个 DF,我总是这样做:

df_new = df1.merge(df2, on='timestamp', how='outer')
df_new = df_new.merge(d3, on='timestamp', how='outer')

然后继续..