Closed mustseetv314 closed 2 months ago
Thanks, ill get on it right now
@mustseetv314 Issue should be fix now, go give it a go and let me know!
Hey @KCNilssen i ran an upgrade on the package, but 0.5.18 isn't pulling down. I see that was the version bump in the fix notes. Thoughts?
@KCNilssen @Mattsface looks like this is why the push failed
hey guys, any thoughts? @KCNilssen @Mattsface
Sorry, Matt should be on it. If its not resolved by tomorrow I'll work on migrating it over to mine.
All good, appreciate it!
On Thu, Apr 11, 2024 at 6:07 PM Kristian Nilssen @.***> wrote:
Sorry, Matt should be on it. If its not resolved by tomorrow I'll work on migrating it over to mine.
— Reply to this email directly, view it on GitHub https://github.com/zero-sum-seattle/python-mlb-statsapi/issues/206#issuecomment-2050694942, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGIUUQ2R7GMUTQ2YPU3IIP3Y44JR3AVCNFSM6AAAAABFVOWMN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJQGY4TIOJUGI . You are receiving this because you were mentioned.Message ID: @.***>
@KCNilssen @Mattsface Looks like another GameInfo.init() adjustment needs to be made. Positional arguments attendance & gamedurationminutes, errors.
Call works for all but 2 gamePK's(745114 & 746083).
Input mlb_games.csv
Output mlb_games_ready.csv
Same code block as previous issue:
Function
Function to get weather and venue for a given game_pk
def get_game_info(game_pk): mlb = mlbstatsapi.Mlb() try: game = mlb.get_game(game_pk) venue_id = game.gamedata.venue.id venue_name = game.gamedata.venue.name venue_lat = game.gamedata.venue.location.defaultcoordinates.latitude venue_long = game.gamedata.venue.location.defaultcoordinates.longitude venue_elevation = game.gamedata.venue.location.elevation venue_surface = game.gamedata.venue.fieldinfo.turftype return venue_id, venue_name, venue_lat, venue_long, venue_elevation, venue_surface except Exception as e: print(f"Error processing game_pk {game_pk}: {e}")
return "None", "None", "None", "None", "None", "None"
Code
Add Game Venue and Location Detail
csv_file = 'mlb_games.csv' df = pd.read_csv(csv_file)
Initialize new columns
df['venue_id'] = None df['venue_name'] = None df['venue_latitude'] = None df['venue_longitude'] = None df['venue_elevation'] = None df['venue_surface'] = None
for index, row in df.iterrows(): game_pk = row['GamePk'] print(game_pk) try: venue_id, venue_name, venue_lat, venue_long, venue_elevation, venue_surface = get_game_info(game_pk) df.at[index, 'venue_id'] = venue_id df.at[index, 'venue_name'] = venue_name df.at[index, 'venue_latitude'] = venue_lat df.at[index, 'venue_longitude'] = venue_long df.at[index, 'venue_elevation'] = venue_elevation df.at[index, 'venue_surface'] = venue_surface except Exception as e: print(f"Error processing game_pk {game_pk}: {e}")
new_column_order = [ 'Date', 'Time', 'GamePk', 'Away Team', 'Home Team', 'venue_id', 'venue_name', 'venue_latitude', 'venue_longitude', 'venue_elevation', 'venue_surface']
Check if all columns are included in new_column_order
assert set(new_column_order) == set(df.columns), "New column order does not match DataFrame columns"
Reindex the DataFrame with the new column order
df = df[new_column_order]
Save the updated DataFrame back to a CSV
updated_csv_file = 'mlb_games_ready.csv' df.to_csv(updated_csv_file, index=False)