<jupyter_start><jupyter_text>__Reshaping__<jupyter_code>import pandas as pd
olympics = pd.read_csv('olympics.csv', skiprows=4)
olympics.head()<jupyter_output><empty_output><jupyter_text>__Athletes winning medals in Beijing Olympics 100m or 200m track event__<jupyter_code>m_08 = olympics[(olympics.Edition == 2008) & 
         ((olympics.Event == '100m') |
         (olympics.Event == '200m'))]
go = m_08.groupby(['NOC','Gender','Discipline','Event']).size()
go
df = go.unstack(['Discipline','Event'])
df<jupyter_output><empty_output><jupyter_text>__Using stack()__<jupyter_code>df.stack()
df.stack('Event')<jupyter_output><empty_output><jupyter_text>__Using unstack()__<jupyter_code>df.unstack('Gender')<jupyter_output><empty_output><jupyter_text>Challenge __Plot the number of gold medals won by the US male and female athletes throughout the history of the Olympics?__<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
olympics.NOC.value_counts()
olympics[(olympics.NOC == 'USA') & (olympics.Medal == 'Gold')].groupby(['Edition','Gender']).size().plot(kind='bar', figsize=(20,7));
us = olympics[(olympics.NOC == 'USA') & (olympics.Medal == 'Gold')]
plt.figure(figsize=(20,7))
sns.countplot(x='Edition', hue='Gender', data=us);<jupyter_output><empty_output><jupyter_text>__Plot the five athletes who have won the most gold medals over the history of the Olympics. When there is a tie, consider the number of silver medals, and the bronze medals.__<jupyter_code>olympics.groupby(['Athlete','Medal']).agg({'Medal':'count'})
df = olympics.groupby(['Athlete','Medal']).size().unstack('Medal', fill_value=0)
df.head()
top = df.sort_values(by=['Gold','Silver','Bronze'], ascending=False)[['Gold','Silver','Bronze']]
top.head()
top.head().plot(kind='bar');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17226197028068244, 'fraction_numerical': 0.015410016510731976, 'mean_word_length': 8.56842105263158, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '107080', 'license': 'MIT', 'n_tokens_mistral': 713, 'n_tokens_neox': 659, 'n_words': 117, 'path': 'Reshaping.ipynb', 'repo_name': 'augustine0890/pandas-Essential', 'size': '1817'}