Skip to content

Instantly share code, notes, and snippets.

@codervince
Created May 27, 2016 05:14
Show Gist options
  • Save codervince/fed0c8d5c268d0de9c638b4ee1ab8243 to your computer and use it in GitHub Desktop.
Save codervince/fed0c8d5c268d0de9c638b4ee1ab8243 to your computer and use it in GitHub Desktop.
PYTHON VS PANDAS
def convert_to_bin_places(seq):
rtn = ""
if '>' in seq:
'''remove > '''
seq = seq.split('>')
rtn = list(map(lambda x: '1' if x != '' and x == '1' else '0', seq))
return "".join(rtn)
def convert_to_fs_places(seq):
rtn = ""
if '>' in seq:
'''remove > '''
seq = seq.split('>')
rtn = list(map(lambda x: x if x != '' and int(x) <= 6 else '0', seq))
return "".join(rtn)
# pandas
results = dictfetchall(cursor)
# list of runners
jsonarray = json.dumps(results,default=outputJSON)
print(jsonarray)
print(len(results))
# next add dates for this period
alldates_idx = pd.date_range(start=startdate, end=enddate, freq='D') # default is calendar day
print(len(alldates_idx)) # 1242 days so far
res_df = pd.read_json(jsonarray, orient='records', convert_dates=['racedate',], dtype={'finalpos': 'string'})
res_df.set_index('racedatetime', inplace=True)
stats['runseq'] = res_df['finalpos'].str.cat(sep='|')
binary_runseq = res_df['finalpos'].apply(won_or_not).str.cat()
stats['binary_runseq']=binary_runseq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment