text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

df = pd.read_csv('/kaggle/input/ufc-fights-2010-2020-with-betting-odds/data.csv')

df = df.dropna()

year_labels = []
for z in range(2010, 2021):
    year_labels.append(z)
fight_counts = []
for z in year_labels:
    fight_counts.append(len(df[df['date'].dt.year == z]))

female_fight_counts = []
for z in year_labels:
    female_fight_counts.append(len(df[(df['date'].dt.year == z) & (df['gender'] == 'FEMALE')]))

df_no_even = df[df['underdog'] != 'Even']
df_no_even = df_no_even[df_no_even['Winner'] != 'Draw']

number_of_fights = len(df_no_even)
number_of_upsets = len(df_no_even[df_no_even['Winner'] == df_no_even['underdog']])
number_of_favorites = len(df_no_even[df_no_even['Winner'] != df_no_even['underdog']])
#print(number_of_upsets)
#print(number_of_fights)
#print(number_of_favorites)
upset_percent = (number_of_upsets / number_of_fights) * 100
favorite_percent = (number_of_favorites / number_of_fights) * 100
#print(upset_percent)
#print(favorite_percent)
labels = 'Favorites', 'Underdogs'
sizes = [favorite_percent, upset_percent]
fig1, ax1 = plt.subplots(figsize=(9,9))
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', textprops={'fontsize': 14})

year_labels
year_fight_counts = []
year_upset_counts = []
year_upset_percent = []
for y in year_labels:
    temp_fights = df_no_even[df_no_even['date'].dt.year == y]
    temp_upsets = temp_fights[temp_fights['Winner'] == temp_fights['underdog']]
    year_fight_counts.append(len(temp_fights))
    year_upset_counts.append(len(temp_upsets))
    year_upset_percent.append(len(temp_upsets) / len(temp_fights))
year_upset_percent = [x * 100 for x in year_upset_percent]
plt.figure(figsize=(9, 5))
barlist = plt.bar(year_labels, year_upset_percent)
plt.xlabel('Year', fontsize=16)
plt.ylabel('Percent of Upset Winners', fontsize=16)
plt.xticks(year_labels, rotation=90)
plt.title('Upset Percentage By Year', fontweight='bold', fontsize=16)
barlist[10].set_color('black')
barlist[3].set_color('grey')