<jupyter_start><jupyter_text>This notebook uses the [GapMinder data set](https://www.gapminder.org)<jupyter_code>import pandas as pd
data = pd.read_csv("data/gapminder.tsv", sep='\t')
data.head() # show five entries<jupyter_output><empty_output><jupyter_text>Using multi-indexing, answer the following questions- Select data about countries in Asia - Select data about countries in Asia in years 1952 to 2000- What is the average `pop` of countries in Asia in years 1952 to 2000<jupyter_code>data[data['continent']=='Asia']
data.set_index('continent').loc['Asia']#.reset_index()
data[(data['continent']=='Asia') & (data['year']>=1952) & (data['year']<=2000)]
data.dtypes
#data2 = data.set_index(['continent', 'year'])
data2 = data.sort_values(['continent', 'year']).set_index(['continent', 'year'])
data2.head()
idx = pd.IndexSlice
#data2.sort_index().loc[idx['Asia', 1952:2000], :]
data3 = data2.loc[idx['Asia', 1952:2000], :]#.reset_index()
data3
data3['pop'].mean()
data2.loc[idx['Asia', 1952:2000], 'pop'].mean()
#data.sort_values(['continent', 'year']).set_index(['continent', 'year']).loc[idx['Asia', 1952:2000], 'pop'].mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20051635111876076, 'fraction_numerical': 0.05593803786574871, 'mean_word_length': 8.15748031496063, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '291701', 'license': 'MIT', 'n_tokens_mistral': 466, 'n_tokens_neox': 401, 'n_words': 84, 'path': '18-warmup-solution_hierarchical_indexing.ipynb', 'repo_name': 'hanisaf/advanced-data-management-and-analytics', 'size': '1162'}