<jupyter_start><jupyter_text>When Updating Master CSV File Start Here!<jupyter_code>import pandas as pd
raw_df = pd.read_csv("data/match_map_stats.csv") #The match stats from https://overwatchleague.com/en-us/statslab
pd.options.mode.chained_assignment = None  #Removes certain warnings
                                                
    
match_ids = raw_df.match_id.unique() #The list of all matches
#Start building the master dataframe
team_one_list = []
team_two_list = []
date_list = []
winner_list = []
stage_list = []


#We use the following loop to go through each match_id and grab information to build the main_dataframe
for m in match_ids:
    temp_df = raw_df[raw_df['match_id'] == m]
    team_one_list.append(temp_df.team_one_name.unique()[0])
    team_two_list.append(temp_df.team_two_name.unique()[0])
    date_list.append(temp_df.round_start_time.unique()[0])
    winner_list.append(temp_df.match_winner.unique()[0])
    stage_list.append(temp_df.stage.unique()[0])
    
#Now that the information is stored in lists we can zip it up and create the working master dataframe
zipped_data = list(zip(match_ids, team_one_list, team_two_list, date_list, stage_list, winner_list))
columns = ['id', 'team_one', 'team_two', 'old_date', 'stage', 'winner']    
df = pd.DataFrame(zipped_data, columns=columns)

df['date'] = ""

#Make sure the date column is in the proper format
df['old_date']=pd.to_datetime(df['old_date'])


#Let's remove the time from datetime.

id_list = df.id.unique()
for i in id_list:
    old_date = ((df[df['id'] == i]).old_date).iloc[0]
    #print(old_date)
    new_date = old_date.date()
    #print(new_date)
    mask = (df['id'] == i)
    df['date'][mask] = new_date
#Drop old_date
df.drop(['old_date'], axis=1, inplace=True)
#Make sure date is properly formatted
df['date']=pd.to_datetime(df['date'])
#We export a template to be used for upcoming matches here
df.to_csv('data/load_upcoming_here.csv')
#Set the corona_virus_isolation feature.  This will be True if games are being played while in isolation because of the pandemic
df['corona_virus_isolation'] = False

#We will use a mask to properly set the feature:
#TODO
mask = (df['date'] > '03/20/2020')
df['corona_virus_isolation'] = mask
#Initiate some features:
df['t1_wins_season'] = ""
df['t1_losses_season'] = ""
df['t2_wins_season'] = ""
df['t2_losses_season'] = ""
df['t1_matches_season'] = ""
df['t2_matches_season'] = ""
df['t1_win_percent_season'] = ""
df['t2_win_percent_season'] = ""
df['t1_wins_alltime'] = ""
df['t1_losses_alltime'] = ""
df['t2_wins_alltime'] = ""
df['t2_losses_alltime'] = ""
df['t1_matches_alltime'] = ""
df['t2_matches_alltime'] = ""
df['t1_win_percent_alltime'] = ""
df['t2_win_percent_alltime'] = ""
df['t1_wins_last_3'] = ""
df['t1_losses_last_3'] = ""
df['t2_wins_last_3'] = ""
df['t2_losses_last_3'] = ""
df['t1_win_percent_last_3'] = ""
df['t2_win_percent_last_3'] = ""
df['t1_wins_last_5'] = ""
df['t1_losses_last_5'] = ""
df['t2_wins_last_5'] = ""
df['t2_losses_last_5'] = ""
df['t1_win_percent_last_5'] = ""
df['t2_win_percent_last_5'] = ""
df['t1_wins_last_10'] = ""
df['t1_losses_last_10'] = ""
df['t2_wins_last_10'] = ""
df['t2_losses_last_10'] = ""
df['t1_win_percent_last_10'] = ""
df['t2_win_percent_last_10'] = ""
df['t1_wins_last_20'] = ""
df['t1_losses_last_20'] = ""
df['t2_wins_last_20'] = ""
df['t2_losses_last_20'] = ""
df['t1_win_percent_last_20'] = ""
df['t2_win_percent_last_20'] = ""
df['t1_place_last_season'] = ""
df['t2_place_last_season'] = ""
df['t1_wins_vs_t2'] = ""
df['t1_losses_vs_t2'] = ""
df['t1_matches_vs_t2'] = ""
df['t1_win_percent_vs_t2'] = ""
df['winner_label'] = ""<jupyter_output><empty_output><jupyter_text>The following are functions that I will use to fill in the features above<jupyter_code>from functions import set_winners, find_last_season_results, find_team_match_results, find_last_n_results 
from functions import find_head_to_head_results
return_df = set_winners(df)
return_df = find_last_season_results(return_df)
return_df = find_team_match_results(return_df, '01/01/2020', '12/31/2020', 'current_season')
return_df = find_team_match_results(return_df, '11/25/2010', '01/01/2080', 'all_time')
return_df = find_team_match_results(return_df, '01/01/2019', '12/31/2019', 'current_season')
return_df = find_team_match_results(return_df, '01/01/2018', '12/31/2018', 'current_season')
return_df = find_last_n_results(return_df, 5)
return_df = find_last_n_results(return_df, 10)
return_df = find_last_n_results(return_df, 3)
return_df = find_last_n_results(return_df, 20)
return_df = find_head_to_head_results(return_df)
display(return_df)
return_df.to_csv('data/overwatch-league.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15355086372360843, 'fraction_numerical': 0.036468330134357005, 'mean_word_length': 6.351097178683386, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '553812', 'license': 'MIT', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1840, 'n_words': 316, 'path': 'create_intial_df.ipynb', 'repo_name': 'shortlikeafox/overwatch-league-owl-data-project', 'size': '4689'}