Hi! I’m Peter Woo, and I’m from Daegu, South Korea. I’m a senior at the College of William and Mary majoring in Data Science and minoring in Anthropology.
This script randomly builds a full roster (without the long snapper) consisting of NFL players in popular American Football videogame Madden 22.
# build_madden_roster.py
#
# CREATED: 09/28/21
# LAST EDIT: 09/28/21
#
# This script randomly builds a full roster (without the long snapper) consisting of NFL players in Madden 22
#
######################################################################################
# REQUIRED MODULES
######################################################################################
import pandas as pd
import random
######################################################################################
# DATA AND FUNCTIONS
######################################################################################
# Dataframe of all players in Madden 22, data retrieved from u/Pestilence_XIV on Reddit r/Madden
# (https://www.reddit.com/r/Madden/comments/ouzjvd/madden_22_player_ratings_spreadsheet_fully/)
= pd.read_csv('https://raw.githubusercontent.com/pterwoo/misc/main/Madden%2022%20Player%20Ratings%20-%20Launch%20(dist).xlsx%20-%20All%20Players.csv')
all_players
# Breakdown of how many players should be in each position
= {"QB": 3,
pos_breakdown "WR": 6,
"HB": 3,
"FB": 1,
"TE": 3,
"C": 2,
"LG": 1,
"RG": 1,
"LT": 2,
"RT": 2,
"LE": 2,
"RE": 2,
"DT": 5,
"LOLB": 3,
"ROLB": 3,
"MLB": 3,
"CB": 4,
"SS": 2,
"FS": 2,
"K": 1,
"P": 1,}
def GetRandomPlayer(position, n):
"""
Features:
- Retrieves random player from the players players database
Inputs:
- position: the position of the player
- n: number of players to choose
Outputs:
- pos: dataframe consisting of the player(s) selected
"""
= all_players['Unnamed: 2'] == position
idx = all_players[idx]
pos_info = pos_info.sample(n = n)
pos return pos
def BuildRoster():
"""
Features:
- Builds the full roster and saves it as a csv file in the selected path
Inputs:
- None
Outputs:
- roster: dataframe containing the full roster
"""
= pd.DataFrame()
roster
for posit in pos_breakdown:
= (int(pos_breakdown.get(posit)))
num_players = GetRandomPlayer(position = posit, n = num_players )
players = roster.append(players)
roster
'your_roster.csv')
roster.to_csv(
######################################################################################
# MAIN
######################################################################################
if __name__ == "__main__":
BuildRoster()
print('Check your current directory for the file your_roster.csv')