Home>

I'm making horse racing prediction software, but I'm trying to calculate the interval for each race.
Since the index is the horse ID, there is duplicate data for each horse race.

tempDf [{'restDifference','raceName','speedScore','date'}]

As a logic to calculate the break

# Breaking calculation process
columnsNum = tempDf.columns.get_loc ('restDifference')
for horseId in tqdm (tempDf.index.unique ()):
    isFirst = True
    beforeDate =''
    count = 0
    restDifference = {}
    for index, row in tempDf [tempDf.index == horseId] .sort_values ​​('date'). iterrows ():
        if isFirst == True:
            isFirst = False
            tempDf [tempDf.index == horseId] .sort_values ​​('date'). Iat [count, columnsNum] = 0
            beforeDate = row ['date']
        else: else:
            tempDf [tempDf.index == horseId] .sort_values ​​('date'). Iat [count, columnsNum] = (row ['date'] --beforeDate) .days
            beforeDate = row ['date']
        count = count + 1
    break
aaa = tempDf [tempDf.index == 2018101626]
aaa [{'restDifference','raceName','speedScore','date'}]

I'm having trouble updating the restDifference value.
Is there any good way?

  • Answer # 1

    # Breaking calculation process
    columnsNum = tempDf.columns.get_loc ('restDifference')
    for horseId in tqdm (tempDf.index.unique ()):
        isFirst = True
        beforeDate =''
        count = 0
        restDifference = tempDf [tempDf.index == horseId] .sort_values ​​('date')
        for index, row in restDifference.iterrows ():
            if isFirst == True:
                isFirst = False
                restDifference.iat [count, columnsNum] = 0
                beforeDate = row ['date']
            else: else:
                restDifference.iat [count, columnsNum] = ((row ['date'] --beforeDate) .days)/7
                beforeDate = row ['date']
            count = count + 1
            tempDf [tempDf.index == horseId] = restDifference

    I was able to do this.
    However, with this, it can be updated only once per second, so it became necessary to speed up.
    I'll throw it in another question.