lundi 29 juin 2015

Data will not parse and extract into excel file?

import pandas as pd 
import os
import time 
from 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] for x in os.walk(statspath)]
df = pd.DataFrame(columns = ['Date','Unix','Ticker','DE Ratio'])

for each_dir in stock_list[1:25]: 
    each_file = os.listdir(each_dir)
    ticker = each_dir.split("\\")[-1] 
    if len(each_file) > 0: 
        for 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()
                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 as e:

save = gather.replace(' ','').replace(')','').replace('(','').replace('/','')+('.csv')


This is my code and everytime I open the excel sheet it just has the headers of the table but non of the data it should be extracting from the files. any idea on why its not copying the data?

Aucun commentaire:

Enregistrer un commentaire