<jupyter_start><jupyter_text>Analysis---  Research Questions:* What is the relationship between gender and disciplines and how does this relationship change over time?*   RQ 1: The Proportion of Genders in the Olympics --- In my ELT I brushed over the relationship between gender and sport discipline and how this relationship changes over time. In this analysis I will be doing a deeper dive into the proportions of men and women in the Olympics thoughout the years, concluding by looking into where we have reached in our most recent data from 2008. Here we have the cleaned version of the data, I have removed a couple redundant variables to make it more concise. This is the dataframe that I will be transforming in order to further explore our data.<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
df = pd.read_csv("../data/processed/data.csv")
df = df.copy().drop(['Country_Code', 'City', 'Athlete', 'Event_gender', 'Unnamed: 0'], axis=1)
df.head()
df2 = df.groupby(["Year","Discipline"]).Gender.value_counts(normalize=True).mul(100).rename('Gender_pct').reset_index()
gender_pct = pd.crosstab(df['Discipline'],df['Gender']).apply(lambda x: (x/x.sum())*100, axis=1)
gender_pct = gender_pct.sort_values(by=['Men'], ascending=True)
gender_proportions2 = sns.lineplot(data=pd.crosstab(df['Year'],df['Gender']).apply(lambda x: (x/x.sum())*100, axis=1))
gender_proportions2.lines[1].set_linestyle("-")
gender_proportions2.legend().get_lines()[1].set_linestyle("-")
gender_proportions2.set_title('Gender Proportions Over Time')
gender_proportions2.axhline(50, ls=':', color='black')<jupyter_output><empty_output><jupyter_text>Here is a plot of how the gender proportions have changed over time. You can see that the proportion of men is falling towards the 50% mark, while the proportion of women climbs up. Clearly, over time we are reaching an equilibrium, this is expecially clear if you observe around 2008, where the proportion is around 47% women. We are approaching an even split between the two. This chart shows valuable information, however, simply observing proportions could lead to a false understanding of the data. This chart could indicate a growth in female participation, but it could equally represent a fall in male participation. We are unable to assume from this graph that the number of women participants has increased, we must use the count of female and male athletes over time to draw any conclusions.<jupyter_code>gender_count = sns.lineplot(data=df.groupby(["Year", "Gender"])["Gender"].count().reset_index(name="Count"), x='Year', y='Count', hue='Gender')
gender_count.set_title('Number of Male/Female Participants over Time')
plt.savefig('gender_count.png', dpi=300)<jupyter_output><empty_output><jupyter_text>This graph is similar to the other plot in that it shows how the gender balance has changed over time. However, this graph shows a count of male and female participants instead of a proportion. This gives another perspective on the situation, showing the growth of each gender instead of showing their growth in relation to one another. This graph displays a growth in both female and male participation, with the count of female athletes having a more significant change. This explains the change in proportions we observed in the previous graph. Let us now look at each individual discipline and how their gender proportions have changed over time.<jupyter_code>gender_proportions = gender_pct.plot(kind='barh', stacked='True', figsize=(8, 10), title='Gender Proportion per Discipline')
gender_proportions.axvline(50, ls=':', color='black')
plt.legend(loc="upper left")<jupyter_output><empty_output><jupyter_text>This stacked barchart displays the proportions of men and women in each discipline, with a divider in the middle indicating the 50% mark. One of the main facts that is pulled from this visualization is that a majority of disciplines in the Olympics tend to lean towards having more male participants than female ones. However, there is also a significant group of disciplines with an equal split between genders. It is worth noting that this a cumulative representation of the data from 1976 to 2008, and not a representation of the current balance of men and women. We must dive into how this proportion has changed over time to have a better understanding of the progression of this data.<jupyter_code>genders2 = gender_pct.reset_index()
data2= df2[df2['Discipline'].isin(list(genders2.Discipline[10:30]))] ##taking the 20 middle disciplines from gender_proportions chart
data2 = data2[data2.Gender != 'Men'] ##dropping 'Men' to focus on data relating to 'Women'
wmn_proportions = sns.lineplot(x='Year', y='Gender_pct', hue = 'Discipline', data=data2, ci=None)
wmn_proportions.set_title('Proportion of Women per Discipline Over Time')
plt.legend(loc="center right", bbox_to_anchor=(1.4, 0.5))
plt.savefig('wmn_proportions.png', dpi=300)<jupyter_output><empty_output><jupyter_text>This last graph shows the how the proportion of women in each sport has changed over time. I decided to use the middle 20 disciplines from the Gender Proportions per Discipline chart because I felt that the disciplines closer to a 50% ratio would have the most interesting growth pattern in that they were less likely to be stagnant than the extremes (like wresling or synchronized swimming. You can see that for almost every discipline there is a steady growth towards the 50% mark. Some disciplines have more change than others, but it is clear that there is an overall shift towards equality over time.<jupyter_code>df2 = df2[df2.Year == 2008].drop(['Year'], axis = 1)
df2 = pd.crosstab(df2['Discipline'],df2['Gender']).apply(lambda x: (x/x.sum())*100, axis=1)
df2 = df2.sort_values(by=['Men'], ascending=True)
gender_proportions_2008 = df2.plot(kind='barh', stacked='True', figsize=(8, 10), title='Gender Proportion per Discipline (2008)')
gender_proportions_2008.axvline(50, ls=':', color='black')
plt.legend(loc="upper left")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08940943582975916, 'fraction_numerical': 0.01930056087099967, 'mean_word_length': 6.066433566433567, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '499112', 'license': 'MIT', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1630, 'n_words': 736, 'path': 'analysis/.ipynb_checkpoints/Analysis-checkpoint.ipynb', 'repo_name': 'data301-2020-winter2/course-project-group_1053', 'size': '6062'}