使用数组输出更新数据帧

时间:2016-01-08 15:57:42

标签: python pandas

我正在尝试将数组中的结果从for循环复制到dataframe。但是,每次尝试此操作时,循环的最后一个值都会在数据框中更新:

counter = 0
sample = [1,2,5,10,15,20,30,60,120,180,240,300,360,420,480,540,600]
columns = ['1','2','5','10','15','20','30','60','120','180','240','300','360','420','480','540','600']

index = df.set_index([df.index])
resultsDf = pd.DataFrame(columns=columns)
resultsDf = pd.DataFrame()
resultsDf.set_index([resultsDf.index])

results = []
for index, rowEntry in TradesGTC.iterrows():#Entry of Trade
    entryVolume = rowEntry[26]
    entryPrice = rowEntry[28]
    ccyPair = rowEntry[12][0:6]    
    entryTime = rowEntry['DateTime']
    for data in sample:        
        exitTime = entryTime + dt.timedelta(seconds = data)
        f = MD.between_time(entryTime,exitTime)
        buy = entryVolume > 0
        sell = entryVolume < 0
        if buy == True:
            maxBidinTimeFrame = f['bid'].max()            
            profit = (maxBidinTimeFrame - entryPrice) * entryVolume
            results.append(profit)
        if sell == True:
            minAskinTimeFrame = f['offer'].min()
            profit = (entryPrice - minAskinTimeFrame) * entryVolume
            results.append(profit)
        resultsDf.append(results)

返回的输出是:

resultsDf

1   2   5   10  15  20  30  60  120 180 240 300 360 420 480 540 600

我希望有一个包含列标题的数据框     1 2 5 10 .... 600 并且每列中列出的结果都会下降......

1 2 3 5 10....600
100 200 100...-50 
.
.

感谢所有帮助 谢谢

1 个答案:

答案 0 :(得分:0)

感谢所有人,但是拼图中缺少的一块......

resultsDf = resultsDf.append(pd.DataFrame(data = results), ignore_index=True)