application_vnd.jupyter.stderr_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

def cleanResults(raceColumns,dfResultsTemp,appendScore):
    for raceCol in raceColumns:
        
        dfResultsTemp.index = dfResultsTemp.index.str.replace(r"(\w)([A-Z])", r"\1 \2")
        dfResultsTemp.index = dfResultsTemp.index.str.title()
        dfResultsTemp.index = dfResultsTemp.index.str.replace('\([A-Z\ 0-9]*\)','')
        dfResultsTemp.index = dfResultsTemp.index.str.strip()
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Riccardo Andrea Leccese','Rikki Leccese')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Nicolas Parlier','Nico Parlier')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Alejandro Climent Hernã¥_ Ndez', 'Alejandro Climent Hernandez')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Alexandre Caizergues','Alex Caizergues')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Florian Trittel Paul','Florian Trittel')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Jean Guillaume Rivaud','Jean-Guillaume Rivaud')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('^Kieran Le$','Kieran Le Borgne')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Marvin Baumeisterschoenian','Marvin Baumeister Schoenian')    
        dfResultsTemp.index = dfResultsTemp.index.str.replace('Theo De Ramecourt','Theo De-Ramecourt')
        dfResultsTemp.index = dfResultsTemp.index.str.replace('James Johnson','James Johnsen')

         
        dfResultsTemp[raceCol] = dfResultsTemp[raceCol].astype(str)
        
        #This code needs cleaning up. Has the important assumptions about what counts as last place and what doesn't count
        dfResultsTemp[raceCol] = dfResultsTemp[raceCol].str.replace('D\+D|DSQ|D\+0|^-[A-Z0-9]*$|\([A-Z0-9\.-]*\)|UFD|SCP|RDG|RCT|DCT|DNS-[0-9]*|DNC-[0-9]*|OCS-[0-9]*|[0-9\.]*DNC|\/','')
        dfResultsTemp[raceCol] = dfResultsTemp[raceCol].str.replace('DNS','')
        
        dfResultsTemp[raceCol] = dfResultsTemp[raceCol].str.replace('RET[0-9]*|DNF-[0-9]*|^DNF$|[0-9\.]*DNF',str(len(dfResultsTemp)+1))
        
        
        dfResultsTemp[raceCol] = pd.to_numeric(dfResultsTemp[raceCol])  
        dfResultsTemp[raceCol] = dfResultsTemp[raceCol] + appendScore
        
    return dfResultsTemp
    

def mergeResults(raceColumns, raceName, dfResultsTemp, dfResults):
    for raceCol in raceColumns:
        raceIndex = raceName + '-' + raceCol
        dfResultsTemp[raceIndex] = dfResultsTemp[raceCol]
        del dfResultsTemp[raceCol]
        dfResults = pd.merge(dfResults, dfResultsTemp[[raceIndex]], left_index=True, right_index=True, how='outer')
    return dfResults

dfResults = pd.DataFrame()