How to loop with time in Python -



How to loop with time in Python -

so i'd compress info downwards minutes. thinking of using loop time? pull info every min range (aka 09:30:00-09:30:59) time between 09:30:00 , 04:00:00, utilize math, , save in pandas dataframe. have no clue how this, , no clue google time loop.

#refrences time import * import urllib.request web import pandas pd import os fortoday = 'http://netfonds.no/quotes/tradedump.php?csv_format=csv&paper=' def pulltoday(exchange,stock): datetoday = strftime("%y-%m-%d", localtime()) filename=('data/'+exchange+'/'+stock+'/'+datetoday+'.txt') try: if not os.path.isdir(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) except oserror: print("something went wrong. review dir creation section") pagebuffer=web.urlopen(fortoday+stock+'.'+exchange) pagedata=pd.read_csv(pagebuffer,usecols=['time','price','quantity']) in pagedata.index: pagedata['time'][i]=pd.datetime.strptime(pagedata['time'][i],'%y%m%dt%h%m%s') pagedata['time'][i]-=pd.datetime.strptime(datetoday+"tz06","%y-%m-%dtz%h") print(pagedata) datafile = open(filename,'w') datafile.write('#format: timestamp;volume;low;high;median\n') datafile.close() pagedata.to_csv(filename,index=false,sep=';',mode='a',header=false) def getlist(filename): stocklist = [] file = open(filename+'.txt', 'r').read() filebylines = file.split('\n') eachline in filebylines: if '#' not in eachline: linebyvalues = eachline.split('.') stocklist.append(linebyvalues) homecoming stocklist start_time = time() stocklist = getlist('stocks') #for eachentry in stocklist: # pulltoday(eachentry[0],eachentry[1]) pulltoday('o','aapl') delay=str(round((time()-start_time))) print('finished in ' + delay)

what do:

for eachminute in pagedata: eachtrade in eachminute: avgpricesum+=quantityoftrade*priceoftrade minutevolume+=quantityoftrade avgpricesum/=minutevolume

python loops pandas stocks

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -