<jupyter_start><jupyter_text>stack() and unstack()<jupyter_code>import pandas as pd
oo = pd.read_csv('data/olympics.csv',skiprows=4)
oo.head()<jupyter_output><empty_output><jupyter_text>Athletes winning medals in Beijing Olympics 100m or 200m track event<jupyter_code>mw = oo[(oo.Edition == 2008) & ( (oo.Event == '100m') | (oo.Event == '200m'))]
mw

g = mw.groupby(['NOC','Gender','Discipline','Event']).size()
g
df = g.unstack(['Discipline','Event'])
df<jupyter_output><empty_output><jupyter_text>stack()<jupyter_code>df
df.stack()
df.stack('Event')<jupyter_output><empty_output><jupyter_text>unstack()<jupyter_code>df
df.unstack()
df.unstack('Gender')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1871345029239766, 'fraction_numerical': 0.024853801169590642, 'mean_word_length': 10.229508196721312, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '582340', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 301, 'n_tokens_neox': 276, 'n_words': 36, 'path': 'basics/first/Ch08 stack() and unstack().ipynb', 'repo_name': 'febin-varghese/Data-Science', 'size': '684'}