Python CSV Clean Up for Greyhounds

Post Reply
User avatar
gazuty
Posts: 2547
Joined: Sun Jun 26, 2011 11:03 am
Location: Green land :)

Over my summer break I am taking baby steps in Python - using PyCharm Community 2020.3

I thought I would start out looking at my last three months of Greyhound Data, so I downloaded that in csv format from my Betfair P&L page.

Those familiar will know that the first column of the csv data is very messy and so I have created a short program to clean it up and prepare a revised excel spreadsheet.

In order to run the program you will need PyCharm Community 2020.3, you will need to have pandas and openpyxl installed and have excel.

After downloading my betfair data I named it "hounds.csv" and put it in the same folder as my PyCharm project. You will see in the red text below you will need to insert your own username into the pathway.

I plan to create a program to analyse this data.

Hope this is helfpul.

/////

import pandas as pd

df = pd.read_csv('hounds.csv')
df.dropna(inplace = True)
df.drop(columns=['Start time', 'Settled date'])
header_list = ['Market', 'Track', 'Date', 'Race', 'Length', 'Profit/Loss (AUD)']
df = df.reindex(columns=header_list)

new = df["Market"].str.split("/", n = 1, expand = True)
df['Market']=new[0]
newc=new[1].str.split(" ", n=2, expand=True)
df['Track']=newc[1]
newc=newc[2].str.split(":", expand=True)
newc['Date']=newc[0].str[-9:]
df['Date']=newc['Date']
newc['Race']=newc[1].str[:3]
df['Race']=newc['Race']
newc['Length']=newc[1].str[4:9]
df['Length']=newc['Length']

df.to_excel (r'C:\Users\XXXX\Desktop\export_dataframe.xlsx', index = False, header=True)
User avatar
Dallas
Posts: 22674
Joined: Sun Aug 09, 2015 10:57 pm
Location: Working From Home

Good work Gazuty

Always good to see new stuff shared to the forum, and Python is something i'd like to get stuck into and begin to learn one day
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

Same here, Dallas. I use VBA to parse the data files but always good to learn something new. I started learning python about a year ago but got knocked off track when covid shut everything down. Hopefully get back into coding in the new yer.
User avatar
mcgoo
Posts: 898
Joined: Thu Jul 18, 2013 12:30 pm

Had to really fiddle with my pycharm interpreter :shock: and working directory (which helped a lot with understanding) to get this to work. Been whiling away my hours with some python learning but chemo and old brain makes for hard yakka :D
Thanks for this gazuty. Look forward to using pandas+python more so I can at least follow what you did :)
User avatar
gazuty
Posts: 2547
Joined: Sun Jun 26, 2011 11:03 am
Location: Green land :)

mcgoo wrote:
Sat Jan 02, 2021 1:05 am
Had to really fiddle with my pycharm interpreter :shock: and working directory (which helped a lot with understanding) to get this to work. Been whiling away my hours with some python learning but chemo and old brain makes for hard yakka :D
Thanks for this gazuty. Look forward to using pandas+python more so I can at least follow what you did :)
Well done McGoo. Hope you beat that bastard cancer. One day we will die, but every day before then we will live. Carpe diem.
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

Gazuty
This is a great little course (dont pay more than 12 GBP for it though
Regards
Peter

https://www.udemy.com/course/python-for-excel-users/
Post Reply

Return to “Trade analysis & record keeping”