0

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

YanRemes
  • 347
  • 2
  • 10
  • 2
    Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Anurag Dabas Jul 21 '21 at 16:15
  • Not really because I have a list of 50 strings and they are not separate variable and each of them carries separate information – YanRemes Jul 21 '21 at 16:50

1 Answers1

1

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
Tejas
  • 391
  • 3
  • 11