text_plain_output_1.png
import pandas as pd

df_medal = pd.read_csv('../input/beijing-2022-olympics/medals.csv')
df_total_medals = pd.read_csv('../input/beijing-2022-olympics/medals_total.csv')
df_events = pd.read_csv('../input/beijing-2022-olympics/events.csv')
df_athletes = pd.read_csv('../input/beijing-2022-olympics/athletes.csv')
s_athletes = pd.read_excel('../input/2021-olympics-in-tokyo/Athletes.xlsx')

d_start = pd.to_datetime(df_events['time'][0])
d_end = pd.to_datetime(df_events['time'][len(df_events) - 1])
days = d_end - d_start
df_og = pd.DataFrame()
competition = ['Summer', 'Winter']
nb_discipline = []
nb_country = []
nb_athlete = []
nb_discipline.append(len(s_athletes['Discipline'].unique()))
nb_discipline.append(len(df_medal['discipline'].unique()))
nb_country.append(len(s_athletes['NOC'].unique()))
nb_country.append(len(df_athletes['country'].unique()))
nb_athlete.append(len(s_athletes['Name'].unique()))
nb_athlete.append(len(df_athletes['name'].unique()))
df_og['competition'] = competition
df_og['disciplines'] = nb_discipline
df_og['countries'] = nb_country
df_og['athletes'] = nb_athlete
df_og
df_og.style.set_caption('Summer vs Winter')

cols = ['medal_type', 'event', 'country', 'discipline']
df_medal = df_medal[cols]
countries = df_total_medals['Country']
nb_d = []
df_medal.drop_duplicates()
for country in countries:
    temp = df_medal.drop_duplicates()[df_medal.drop_duplicates()['country'] == country]
    temp_2 = temp['discipline']
    temp_2 = temp_2.drop_duplicates()
    nb_d.append(len(temp_2))
df_total_medals['Discipline'] = nb_d

athletes = pd.read_csv('../input/beijing-2022-olympics/athletes.csv')
athletes = athletes.rename(columns={'discipline': 'Discipline', 'country': 'Country'})
cols = ['gender', 'Discipline']
gender = athletes[cols]

gender['M'] = 0
gender['F'] = 0
i = 0
while i < len(gender['gender']):
    if gender['gender'][i] == 'Male':
        gender['M'][i] = 1
    else:
        gender['F'][i] = 1
    i += 1
gender['Male'] = gender.groupby('Discipline')['M'].transform('sum')
gender['Female'] = gender.groupby('Discipline')['F'].transform('sum')
del gender['gender']
del gender['M']
del gender['F']
gender = gender.drop_duplicates()
gender = gender.iloc[:-1, :]
gender['Total'] = gender['Male'] + gender['Female']
total_male = int(gender['Male'].sum())
total_female = int(gender['Female'].sum())

print('There is a total of', total_male, 'male and', total_female, 'female for the Beijing 2022 Olympic Games')