2014-11-02 4 views
1

나는 주식 틱 데이터를 다루기 위해 pandas와 함께 python을 사용하고 있으며 낮, 최고, 최저, 평균 25 %의 전체 볼륨으로 압축하려고합니다. 무역 볼륨의 75 %. 나는 25 %와 75 % 수준이 어디에 있는지를 찾는 방법을 확신하지 못합니다.Python pandas가 중간을 찾는다

#Refrences 
from time import * 
import urllib.request as web 
import pandas as pd 
import os 

dateToday = "2014-10-31" 

def pullData(exchange,stock,date): 
    baseUrl='http://netfonds.no/quotes/tradedump.php?csv_format=csv' 
    fullUrl=baseUrl+'&date='+date.replace("-","")+'&paper='+stock+'.'+exchange 
    fileName=('netfonds/trades/'+stock+'.txt') 
    try: 
     if not os.path.isdir(os.path.dirname(fileName)): 
      os.makedirs(os.path.dirname(fileName)) 
    except OSError: 
     print("Directory Error") 
    #print(fullUrl)  
    webBuffer=web.urlopen(fullUrl) 
    webData=pd.read_csv(webBuffer,usecols=['price','quantity']) 
    low = webData['price'].min() 
    high = webData['price'].max() 
    print(low,high) 


def getList(fileName): 
    stockList = [] 
    file = open(fileName+'.txt', 'r').read() 
    fileByLines = file.split('\n') 
    for eachLine in fileByLines: 
     if '#' not in eachLine: 
      lineByValues = eachLine.split('.') 
      stockList.append(lineByValues) 
    return stockList 

def fromList(): 
    print("Parsing stock tickers...") 
    stockList = getList('stocks') 
    print("Found "+str(len(stockList))+" stocks") 

    for eachEntry in stockList: 
     start_time = time() 
     try: 
      print("Attempting to pull data for "+eachEntry[1]) 
      pullData(eachEntry[0],eachEntry[1],dateToday) 
      print("Pulled succcessfully in "+str(round(time()-start_time))+" seconds") 
     except Exception: 
      print("Unable to pull data... "+eachEntry[1]) 

first_time = time() 
fromList() 
print("Program Finished! Took "+str(round((time()-first_time)/60))+' minutes') 
+0

스택 오버 플로우에 오신 것을 환영합니다! 당신이 작성한 코드를 게시 할 수 있습니까? – tsnorri

+0

감사합니다. 지금까지 코드를 추가했습니다. –

+0

['describe'] (http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html#pandas.DataFrame.describe) 이미 이것을 수행합니다 – EdChum

답변

0

을().

inflated=pd.DataFrame(np.repeat(webData['price'].values,webData['quantity'].values)) 
+0

그런 다음 대답을 수락하십시오. – hd1

+0

아직 허용되지 않습니다. –

1

pandas 시리즈 및 DataFrame가 R의 요약과 비슷한 설명 방법이 : 나는 단순히 numpy.repeat를 사용하여 필요한 것을 발견

In [3]: import numpy as np 

In [4]: import pandas as pd 

In [5]: s = series.values() 

In [6]: s.describe() 
Out[6]: 
count 100.000000 
mean  0.540376 
std  0.296250 
min  0.002514 
25%  0.268722 
50%  0.593436 
75%  0.831067 
max  0.991971 
+0

음, 서로 독립적 인 통계를하고 있습니다. 수량 열이 가격 열의 빈도 목록으로 필요합니다. –

+0

그런 다음 수량 열을 가격 열의 빈도 목록으로 지정하십시오. – hd1

관련 문제