<jupyter_start><jupyter_text>Importing data<jupyter_code>matches = pd.read_csv("matches.csv")
matches.head()
attributes = pd.read_csv("attributes.csv")
attributes.head()
batsmen = open('batsmen.json',) 
batsmen_data = json.load(batsmen)
bowlers = open('bowlers.json',) 
bowlers_data = json.load(bowlers)
invtmap = open('invtmap.json',) 
invtmap_data = json.load(invtmap)
scorecard = open('scorecard.json',) 
scorecard_data = json.load(scorecard)
region = open('region.json',) 
region_data = json.load(region)
tmap = open('tmap.json',) 
tmap_data = json.load(tmap)<jupyter_output><empty_output><jupyter_text>Making the Database<jupyter_code>countries = list(set(matches['Team_1'].tolist()) | set(matches['Team_2'].tolist()))
countries
ground = list(set(matches['GroundCode'].tolist()) )
#ground
#Input
team_1 = 'IND'
team_2 = 'ZIM' 
venue = 26
date = '2015-07-12'

match_1 = matches[matches['Date']==date]
match = match_1[match_1['Team_1']==team_1]
match_code = match['MatchCode'].tolist()[0]
score_card = scorecard_data[str(match_code)]
team_1_players = [score_card['BATTING1'][i][0] for i in range(10)]
team_2_players = [score_card['BATTING2'][i][0] for i in range(10)]
#name
team_1_players_name = [attributes[attributes['Code']==team_1_players[i]].iloc[0]['Full Name'] for i in range(10)]
team_2_players_name = [attributes[attributes['Code']==team_2_players[i]].iloc[0]['Full Name'] for i in range(10)]
#Batting style
team_1_players_bats = [attributes[attributes['Code']==team_1_players[i]].iloc[0]['Bats'] for i in range(10)]
team_2_players_bats = [attributes[attributes['Code']==team_2_players[i]].iloc[0]['Bats'] for i in range(10)]
#Bowling style
team_1_players_bowls = [attributes[attributes['Code']==team_1_players[i]].iloc[0]['Bowls'] for i in range(10)]
team_2_players_bowls = [attributes[attributes['Code']==team_2_players[i]].iloc[0]['Bowls'] for i in range(10)]
#Form for each player

years_to_take_in = 5 #number of years to go back for dataset
matches_needed_for_dataset = matches[matches['Team_1']==team_1]
matches_needed_for_dataset = matches_needed_for_dataset[matches_needed_for_dataset['Team_2']==team_2]
matches_needed_for_dataset['Date']= pd.to_datetime(matches_needed_for_dataset['Date'])
date_obj = datetime.datetime.strptime(date, '%Y-%m-%d')
date_obj_min = datetime.datetime.strptime(str(date_obj.year-years_to_take_in)+'-01'+'-01', '%Y-%m-%d')
matches_needed_for_dataset = matches_needed_for_dataset[matches_needed_for_dataset['Date']>=date_obj_min]
Dataset = matches_needed_for_dataset.reset_index()
MatchCodes = Dataset['MatchCode'].tolist()
Dataset = Dataset.drop(columns=['index'])
Dataset['Toss'] = ''
Dataset['Fours_team1'] = ''
Dataset['Fours_team2'] = ''
Dataset['Sixes_team1'] = ''
Dataset['Sixes_team2'] = ''
Dataset['Strike_rate_team1'] = ''
Dataset['Strike_rate_team2'] = ''
Dataset['Maidens_team1'] = ''
Dataset['Maidens_team2'] = ''
Dataset['Wickets_team1'] = ''
Dataset['Wickets_team2'] = ''
Dataset['Economy_rate_team1'] = ''
Dataset['Economy_rate_team2'] = ''
Dataset['Result'] = ''
for i in range(len(MatchCodes)):
    matchdata = scorecard_data[str(MatchCodes[i])]
    #Dataset = Dataset.drop(columns=['GroundCode','Team_1','Team_2'])
    if (matchdata['TOSS']==matchdata['ORDER'][0]):
        toss = team_1
    else:
        toss = team_2
    #Batting 1
    batting1 = matchdata['BATTING1']
    Runs_team1 = []
    Balls_Played_team1 = []
    Fours_team1 = []
    Sixes_team1 = []
    Strike_rate_team1 = []
    for val in range(10):
        Runs_team1.append(batting1[val][2])
        Balls_Played_team1.append(batting1[val][3])
        Fours_team1.append(batting1[val][4])
        Sixes_team1.append(batting1[val][5])
        Strike_rate_team1.append(batting1[val][6])
        
    #Batting 2
    batting2 = matchdata['BATTING2']
    Runs_team2 = []
    Balls_Played_team2 = []
    Fours_team2 = []
    Sixes_team2 = []
    Strike_rate_team2 = []
    for val in range(10):
        Runs_team2.append(batting2[val][2])
        Balls_Played_team2.append(batting2[val][3])
        Fours_team2.append(batting2[val][4])
        Sixes_team2.append(batting2[val][5])
        Strike_rate_team2.append(batting2[val][6])

    #Bowling 1
    bowling1 = matchdata['BOWLING1']
    Overs_team1 = []
    Maidens_team1 = []
    Runs_given_team1 = []
    Wickets_team1 = []
    Economy_rate_team1 = []
    for val in range(10):
        if val<len(bowling1):
            Overs_team1.append(bowling1[val][1])
            Maidens_team1.append(bowling1[val][2])
            Runs_given_team1.append(bowling1[val][3])
            Wickets_team1.append(bowling1[val][4])
            Economy_rate_team1.append(bowling1[val][5])
        else:
            Overs_team1.append(-1)
            Maidens_team1.append(-1)
            Runs_given_team1.append(-1)
            Wickets_team1.append(-1)
            Economy_rate_team1.append(-1)

    #Bowling 2
    bowling2 = matchdata['BOWLING2']
    Overs_team2 = []
    Maidens_team2 = []
    Runs_given_team2 = []
    Wickets_team2 = []
    Economy_rate_team2 = []
    for val in range(10):
        if val<len(bowling2):
            Overs_team2.append(bowling2[val][1])
            Maidens_team2.append(bowling2[val][2])
            Runs_given_team2.append(bowling2[val][3])
            Wickets_team2.append(bowling2[val][4])
            Economy_rate_team2.append(bowling2[val][5])
        else:
            Overs_team2.append(-1)
            Maidens_team2.append(-1)
            Runs_given_team2.append(-1)
            Wickets_team2.append(-1)
            Economy_rate_team2.append(-1)
    #Scores
    score = matchdata['SCORES']
    if (score[0]>score[1]):
        result = team_1
    elif (score[1]>score[0]):
        result = team_2
    else:
        result = 'Tie'
    
    #insert into dataset
    Dataset['Toss'].iloc[i] = toss
    Dataset['Fours_team1'].iloc[i] = Fours_team1
    Dataset['Fours_team2'].iloc[i] = Fours_team2
    Dataset['Sixes_team1'].iloc[i] = Sixes_team1
    Dataset['Sixes_team2'].iloc[i] = Sixes_team2
    Dataset['Strike_rate_team1'].iloc[i] = Strike_rate_team1
    Dataset['Strike_rate_team2'].iloc[i] = Strike_rate_team2
    Dataset['Maidens_team1'].iloc[i] = Maidens_team1
    Dataset['Maidens_team2'].iloc[i] = Maidens_team2
    Dataset['Wickets_team1'].iloc[i] = Wickets_team1
    Dataset['Wickets_team2'].iloc[i] = Wickets_team2
    Dataset['Economy_rate_team1'].iloc[i] = Economy_rate_team1
    Dataset['Economy_rate_team2'].iloc[i] = Economy_rate_team2
    Dataset['Result'].iloc[i] = result
Dataset.head()
Dataset = Dataset.drop(columns=['Date','Team_1','Team_2','MatchCode','GroundCode'])
Dataset<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15716440422322775, 'fraction_numerical': 0.03619909502262444, 'mean_word_length': 4.558256496227997, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '636024', 'license': 'MIT', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2561, 'n_words': 311, 'path': 'analysis/Data preprocessing (nikhil).ipynb', 'repo_name': 'someshsingh22/TeamEleven', 'size': '6630'}