Reputation: 337
I have a list of strings with tickers
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 dataset looks like this
2021:03:21 | 33.45
2021:03:22 | 33.50
2021:03:23 | 33.60
2021:03:24 | 33.70
GME dataset looks like this
2021:03:21 | 10.45
2021:03:22 | 11.50
2021:03:23 | 12.60
2021:03:24 | 12.65
I want to combine these two datasets to look like this
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
Here is what I have tried
for combine in tickers:
df = pd.DataFrame(combine)
df.concat(df[combine])
I know that it doesn't work. I don't know other methods to combine two datasets into one with common time column. I would appreciate your hint thank you
Upvotes: 0
Views: 679
Reputation: 401
You can do it like this
df=None
flag=False
for combine in tickers:
if not Flag:
df = pd.DataFrame(combine)
flag=True
else:
df_t = pd.DataFrame(combine)
df = df.merge(df_t, on='time')
df
Upvotes: 1