Search code examples
pythonpandasdataframecsvyfinance

Read a csv file into Pandas dataframe yfinance with a tickercode as filename


I'm trying to read a csv file into a Pandas dataframe with a ticker variable as filename, but I can't find a Function to read the csv file, for the 5x?????. And it is important that it is with a ticker code as a file name, because I have already received several suggestions with pd.read_csv('value.txt'), and that is not what I am looking for. Can anyone help

import pandas as pd
from pandas_datareader import data as pdr
yf.pdr_override

for ticker in tickers:
    print(ticker)
    df = pdr.?????('daily_stock_dfs/{}.csv'.format(ticker))
    df = rsi_calculator(df)
print('END')

Solution

  • read_csv() is what you are looking for.

    This will create a dataframe by reading in a csv. The ticker string can be concatenated in many ways.

    df = pd.read_csv('daily_stock_dfs/' + ticker + '.csv')

    or

    df = pd.read_csv('daily_stock_dfs/{}.csv'.format(ticker))