Data will not parse and extract into excel file? -
import pandas pd import os import time datetime import datetime path = "c:\\users\s\downloads\h\intraquarter" def key_stats(gather = "total debt/equits (mrq) "): statspath = path + '/_keystats' stock_list = [x[0] x in os.walk(statspath)] df = pd.dataframe(columns = ['date','unix','ticker','de ratio']) each_dir in stock_list[1:25]: each_file = os.listdir(each_dir) ticker = each_dir.split("\\")[-1] if len(each_file) > 0: file in each_file: date_stamp = datetime.strptime(file, '%y%m%d%h%m%s.html') unix_time = time.mktime(date_stamp.timetuple()) full_file_path = each_dir+'/'+file source = open(full_file_path,'r').read() try: value = float(source.split(gather+':</td><td class="yfnc_tabledata1">')[1].split('</td>')[0]) df - df.append({'date':date_stamp,'unix':unix_time,'ticker':ticker,'de ratio':value,}, ignore_index = true) except exception e: pass save = gather.replace(' ','').replace(')','').replace('(','').replace('/','')+('.csv') print(save) df.to_csv(save) key_stats()
this code , everytime open excel sheet has headers of table non of data should extracting files. idea on why not copying data?
Comments
Post a Comment