<jupyter_start><jupyter_text>Importing<jupyter_code>from selenium import webdriver 
from selenium.webdriver.common.keys import Keys
import requests
from bs4 import BeautifulSoup 
import re
import pandas as pd 
import os 
import time
import datetime
import csv
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from __future__ import division<jupyter_output><empty_output><jupyter_text>Reading the 3 workouts dfs to clean<jupyter_code>apr14_workouts = pd.read_csv('workouts_csv')
apr7_workouts = pd.read_csv('workouts_csv_2')
apr6_workouts = pd.read_csv('workouts_csv_3')
allworkouts_uncleaned = pd.concat([apr14_workouts, apr7_workouts, apr6_workouts], axis=0)
allworkouts_uncleaned.to_csv('allworkouts_uncleaned')<jupyter_output><empty_output><jupyter_text>allworkouts_uncleaned = pd.read_csv('allworkouts_uncleaned')<jupyter_code>len(allworkouts_uncleaned)
allworkouts_uncleaned.sample(10)
allworkouts_clean = allworkouts_uncleaned.drop('Unnamed: 0', axis=1).drop('Course', axis=1).drop('Note', axis=1 ).drop('Rank', axis=1).drop('Track',axis=1)


allworkouts_clean
Practice_days = allworkouts_clean.groupby(['Horse Name']).Date.count().reset_index()
#Practice_days = allworkouts_clean.groupby((['Horse Name']).Date isin '\17')

#Practice_counts = allworkouts_clean.groupby(['Horse Name']).Distance.value_counts()
#allworkouts_clean3 = allworkouts_clean2[(allworkouts_clean2.Distance == "4F") | (allworkouts_clean2.Distance == "5F") 
Practice_days.head(10) ###Combine into final data frame. 
#allworkouts_clean = allworkouts_clean.filter['5F','4F']

#allworkouts_clean = (allworkouts_clean['Distance'] == '5F') or (allworkouts_clean['Distance'] == '4F')

#FiveF = allworkouts_clean['Distance'] != "2F","3F","6F"
#FourF = allworkouts_clean['Distance'] == "4F"
#allworkouts_clean = allworkouts_clean[FiveF]<jupyter_output><empty_output><jupyter_text>Creating df from workouts df of number of practice days<jupyter_code>allworkouts_clean2 = allworkouts_clean.groupby(['Horse Name', "Distance"]).Time_tenths_second.agg([np.mean]).reset_index()
allworkouts_clean3 = allworkouts_clean2[(allworkouts_clean2.Distance == "4F") | (allworkouts_clean2.Distance == "5F") | (allworkouts_clean2.Distance == "3F")]
allworkouts_clean3.head(10)
allworkouts_clean4 = allworkouts_clean3.pivot(index='Horse Name', columns='Distance', values='mean').reset_index()


#allworkouts_clean4 = allworkouts_clean3.unstack(level=-1)
allworkouts_clean4.head(10)
allworkouts_clean4.to_csv('workout_means')<jupyter_output><empty_output><jupyter_text>Combining final DF<jupyter_code>#Merging all the workout dataframes
apr14_final = pd.read_csv('final_merged')
apr7_final = pd.read_csv('final_merged2')
apr6_final = pd.read_csv('final_merged3')
finalmerged_uncleaned = pd.concat([apr14_final, apr7_final, apr6_final], axis=0)
finalmerged_uncleaned.to_csv('final_Times.csv')
finalmerged_uncleaned = pd.read_csv('final_Times.csv').drop('Unnamed: 0', axis=1)
#Adding the percentage of the time the horse places in a race. 
finalmerged_uncleaned["PercentWin"] = (finalmerged_uncleaned["Firsts"] + finalmerged_uncleaned["Seconds"]+ finalmerged_uncleaned["Thirds"])/ (finalmerged_uncleaned["Starts"])
finalmerged_uncleaned.head(2)
#Merging the final times df with the #of practice days df
finalmerged_clean = pd.merge(finalmerged_uncleaned,Practice_days,on='Horse Name', how = 'left')
finalmerged_clean.head(2)
#Merging the merged data frame, with the workouts df
finalmerged_clean = pd.merge(finalmerged_clean,allworkouts_clean4,on='Horse Name', how = 'left')
finalmerged_clean.head(2)
#Renaming the columns so they don't confuse the model later.
finalmerged_clean = finalmerged_clean.rename(columns={'3F':'ThreeF'}).rename(columns={'4F':'FourF'}).rename(columns={'5F':'FiveF'}).fillna(0)
finalmerged_clean
finalmerged_clean.shape
finalmerged_clean.to_csv('finalmerged_clean')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12975334018499485, 'fraction_numerical': 0.02081192189105858, 'mean_word_length': 10.059659090909092, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '346298', 'license': 'Apache-2.0', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1395, 'n_words': 226, 'path': 'Horse Race Data - Race time prediction/.ipynb_checkpoints/Step2_DataCleaning-checkpoint.ipynb', 'repo_name': 'vszuflita/Metis', 'size': '3892'}