1

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')
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
jhjorsal
  • 197
  • 3
  • 10
  • `df = pd.readcsv('daily_stock_dfs/' + ticker + '.csv')` <- You say this is not what you are looking for but you don't explain why. From your description this is what you are asking for.... – Unfitacorn Dec 12 '19 at 09:03
  • Sorry I meant `read_csv` – Unfitacorn Dec 12 '19 at 09:09
  • Sorry, I am a newbee, that was exactly what I was looking for, I just couldn't see how I got my ticker code into the file name, but it couldn't be made much simpler, super thanks – jhjorsal Dec 12 '19 at 09:51
  • Please except my answer below. In future try to put in as much information as you can that will help an outsider of the project to understand what you are looking for. For example - is ticker just a string? what use is `print(ticker)` to someone trying to answer you. It comes with practice :) – Unfitacorn Dec 12 '19 at 11:48
  • Yes I know, but sometimes I forget that that nobody can know what I am thinking. – jhjorsal Dec 12 '19 at 16:45
  • Does this answer your question? [How to read in the multi-index columns from csv and return the yfinance dataframe to the correct form?](https://stackoverflow.com/questions/63107594/how-to-read-in-the-multi-index-columns-from-csv-and-return-the-yfinance-datafram) – Trenton McKinney Aug 03 '20 at 23:31

1 Answers1

1

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))

Unfitacorn
  • 186
  • 2
  • 12