수학 모델링 처리 데이터

import pandas as pd
import numpy as np
d1 = []
df4 = []
a = []
b = []
i = 0
data = pd.read_excel('jijin.xlsx', header=0)
d5 = data['NAV']
with open('sharp.txt','r') as f:
    lines = f.readlines()

def statistics(f,ord,data):
    s = f
    x = ord
    while f == s:
        if ord == len(data['Symbol']):
            return ord-x
        f = data['Symbol'][ord]
        ord += 1
    return ord-1-x

while i < len(data['Symbol']):
    num = statistics(data['Symbol'][i],i,data)
    print 'num : ',num
    df4.append(num)
    j = 0
    m = 0
    while j< 3:
        a.append(0)
        j += 1
    while m < 3:
        b.append(0)
        m += 1
    i += 3
    s = i
    while i < s+num - 6:
        d2 = []
        for x in [-3,-2,-1,0,1,2,3]:
            d2.append(d5[i+x])
        d2 = np.array(d2)
        d3 = np.max(d2)
        d4 = np.min(d2)
        if d3 == d5[i] or d4 == d5[i]:
            a.append(1),b.append(0)
        else:
            a.append(0),b.append(1)
        i +=1
    j = 0
    m = 0
    while j< 3:
        a.append(0)
        j += 1
    while m < 3:
        b.append(0)
        m += 1
    i +=3

def search(s,lines):
    for da in lines:
        d = da.split(',')
        i = int(d[0])
        if s == i:
            return d[1]

s = 0
for c in data['Symbol']:
    if c == s:
        d1.append(float(e))
    else:
        e = search(c,lines)
        d1.append(float(e))
        s = c
l = len(df4)
df1 = pd.DataFrame(a,index = np.arange(len(data['Symbol'])),columns = ['a'] )
df2 = pd.DataFrame(b,index = np.arange(len(data['Symbol'])),columns = ['b'] )
df3 = pd.DataFrame(d1,index = np.arange(len(data['Symbol'])),columns = ['sharp'] )
df4 = pd.DataFrame(df4,index = np.arange(l),columns = ['numbers'] )
data.insert(5,'a',df1)
data.insert(6,'b',df2)
data.insert(7,'sharp',df3)
data.insert(8,'numbers',df4)
data.to_excel('test_add10.xlsx')

좋은 웹페이지 즐겨찾기