Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nan or Inf values at avg shot/player speed (first few frames) #13

Open
Sh-31 opened this issue Aug 6, 2024 · 0 comments
Open

Nan or Inf values at avg shot/player speed (first few frames) #13

Sh-31 opened this issue Aug 6, 2024 · 0 comments

Comments

@Sh-31
Copy link

Sh-31 commented Aug 6, 2024

  • When calculating player (1/2) average (shot/player) speed we divide by zero because there are no shots yet so we get nan values.
# tennis_analysis/main.py
# lines 118 - 121
player_stats_data_df['player_1_average_shot_speed'] = player_stats_data_df['player_1_total_shot_speed']/player_stats_data_df['player_1_number_of_shots']
player_stats_data_df['player_2_average_shot_speed'] = player_stats_data_df['player_2_total_shot_speed']/player_stats_data_df['player_2_number_of_shots']
player_stats_data_df['player_1_average_player_speed'] = player_stats_data_df['player_1_total_player_speed']/player_stats_data_df['player_2_number_of_shots']
player_stats_data_df['player_2_average_player_speed'] = player_stats_data_df['player_2_total_player_speed']/player_stats_data_df['player_1_number_of_shots']

image

  • One way to fix it is to use .fillna(0)
   # Calculate average speeds and replace NaNs with 0
player_stats_data_df['player_1_average_shot_speed'] = (player_stats_data_df['player_1_total_shot_speed'] / player_stats_data_df['player_1_number_of_shots']).fillna(0)
player_stats_data_df['player_2_average_shot_speed'] = (player_stats_data_df['player_2_total_shot_speed'] / player_stats_data_df['player_2_number_of_shots']).fillna(0)
player_stats_data_df['player_1_average_player_speed'] = (player_stats_data_df['player_1_total_player_speed'] / player_stats_data_df['player_1_number_of_shots']).fillna(0)
player_stats_data_df['player_2_average_player_speed'] = (player_stats_data_df['player_2_total_player_speed'] / player_stats_data_df['player_2_number_of_shots']).fillna(0)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant