Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 649

How to solve a Pandas datareader yahoo scraping problem?

$
0
0

I have a python program that I wrote 15+ years ago when I was still in my 60's. The program stopped working about a week ago due to the addition of a multi-level header. I've spent a week or more trying everything I could think of to fix this problem. I suspect I need to add .xs to my code somewhere???

Any help would be greatly appreciated!!!

Code:

from pandas_datareader import data as pdrfrom openpyxl import load_workbookfrom openpyxl.utils.dataframe import dataframe_to_rowsfrom openpyxl.utils import get_column_letter# pd.core.common.is_list_like = pd.api.types.is_list_liketoday = date.today()with open('F:\\Documents\\PythonLocal\\Yahoo Data\\YahooSymbols Full.txt', 'r') as infile:    symbols = infile.readlines()   # Created a list of all symbols in the filedf = "AAA"begin = date.today()-timedelta(5)print(begin)end = date.today()-timedelta(0)print(end)wb = load_workbook('F:\\Documents\\PythonLocal\\Yahoo Data\\YahooHistorical Data.xlsx')wb.create_sheet(str(today))ws = wb[str(today)]i = get_column_letter(1)ws.column_dimensions[i].width = 24for symbol in symbols:    i = 0    for letter in symbol:        i = i + 1        if i == len(symbol) and letter == '\n':            symbol = symbol[:-1]            idx = 6            df = pdr.get_data_yahoo(str(symbol), begin, end) *****            df(loc=idx, column='Symbol', value=str(symbol))            df.index.name = None    for r in dataframe_to_rows(df, index=True, header=False):        ws.append(r)wb.save('F:\\Documents\\PythonLocal\\Yahoo Data\\YahooHistorical Data.xlsx')wb.close()

Note:

  1. the ***** location is where I think the .xs should go????
  2. The input file is a simple .txt list of stock symbols

TIA Doug


Viewing all articles
Browse latest Browse all 649

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>