-2

I want to create a dataframe with values for each ticker i'm making a request.

Each data frame needs to have the name of each ticker name so when i call the variable MMM i will get data from MMM ticker.

import pandas as pd
import yfinance as yf

tickets = ['MMM',
 'ABT',
 'ABBV',
 'ABMD',
 'ACN',
 'ATVI']

for i in tickets:

    value = yf.download(str(i), start = "2017-06-14", end = "2021-06-14", interval="1d")
    value = i = value['Adj Close']

In the end, I want to have 6 variables with the name of each ticker.

  • Does this answer your question? [How do I create variable variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables) – Pranav Hosangadi Jun 16 '21 at 16:47

1 Answers1

1

Store your frames in a dictionary with the ticker name as the key. Then you call each frame based on the key:

data = {tick: yf.download(tick, start = "2017-06-14", end = "2021-06-14", interval="1d")['Adj Close'] for tick in tickets}
data['MMM'] # call the MMM frame
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41