如何将两个不同的数据集合并或连接为一个

2024-06-02 12:37:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个带标记的字符串列表

tickers = [AA, GME...]
It is just an example I have a variable with 50 tickers
50_tickers = [AA,GME,FB,MSFT...] 50 of them
And I need to combine all of them following the same pattern as below

AA数据集看起来像这样

2021:03:21 | 33.45
2021:03:22 | 33.50
2021:03:23 | 33.60
2021:03:24 | 33.70

GME数据集如下所示

2021:03:21 | 10.45
2021:03:22 | 11.50
2021:03:23 | 12.60
2021:03:24 | 12.65

我想把这两个数据集合并成这样

time | price AA | price GME
2021:03:21 | 33.45 | 10.45
2021:03:22 | 33.50 | 11.50
2021:03:23 | 33.60 | 12.60
2021:03:24 | 33.70 | 12.65

这是我试过的

for combine in tickers:
df = pd.DataFrame(combine)
df.concat(df[combine])

我知道这不管用。我不知道其他方法将两个数据集合并为一个具有公共时间列的数据集。 谢谢你的提示 多谢各位


Tags: of数据字符串标记df列表isit