<jupyter_start><jupyter_text>IntroductionIn workspaces like this one, you will be able to practice visualization techniques you've seen in the course materials. In this particular Jupyter Notebook, you'll practice creating single-variable plots for categorical data.The cells where you are expected to contribute, are highlighted with **TO DO** markdown.<jupyter_code># prerequisite package imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb

%matplotlib inline

# The `solutions_univ.py` is a Python file available in the Notebook server that contains solution to the TO DO tasks.
# The solution to each task is present in a separate function in the `solutions_univ.py` file. 
# Do not refer to the file untill you attempt to write code yourself. 
from solutions_univ import bar_chart_solution_1, bar_chart_solution_2<jupyter_output><empty_output><jupyter_text>About the DatasetIn this workspace, you'll be working with the dataset comprised of attributes of creatures in the video game series Pokémon. The data was assembled from the database of information found in this [GitHub repository](https://github.com/veekun/pokedex/tree/master/pokedex/data/csv).<jupyter_code>pokemon = pd.read_csv('./data/pokemon.csv')
pokemon.head()<jupyter_output><empty_output><jupyter_text>**TO DO Task 1** 1. Explore the `pokemon` dataframe, and try to understand the significance of each of its column.2. There have been quite a few Pokémon introduced over the series' history. Display the count of Pokémon introduced in each generation? Create a _bar chart_ of these frequencies using the 'generation_id' column.<jupyter_code># YOUR CODE HERE
pokemon['generation_id'].value_counts()
base_color=sb.color_palette()[0]
sb.countplot(x=pokemon['generation_id'], color=base_color)<jupyter_output><empty_output><jupyter_text>Expected Output: TO DO Task 1 Once you've created your chart, run the cell below to check the output from our solution. **Your visualization does not need to be exactly the same as ours, but it should be able to come up with the same conclusions.**<jupyter_code># The function below has been defined in the `solutions_univ.py` file, that you can refer only when necessary. 
# This function contains the expected solution. 
bar_chart_solution_1()<jupyter_output>I used seaborn's countplot function to generate this chart. I also added an additional argument so that each bar has the same color.<jupyter_text>**TO DO Task 2** 1. Each Pokémon species has either `type_1`, `type_2` or both `types` that play a part in its offensive and defensive capabilities. The code below creates a new dataframe `pkmn_types` that club the rows of both `type_1` and `type_2`, so that the resulting dataframe has **new** column, `type_level`. **Display, how frequent is each type?**The function below will do the following in the pokemon dataframe *out of place*:1. Select the 'id', and 'species' columns from pokemon. 2. Remove the 'type_1', 'type_2' columns from pokemon3. Add a new column 'type_level' that can have a value either 'type_1' or 'type_2'4. Add another column 'type' that will contain the actual value contained in the 'type_1', 'type_2' columns. For example, the first row in the pokemon dataframe having `id=1`	and `species=bulbasaur` will now occur twice in the resulting dataframe after the `melt()` operation. The first occurrence will have `type=grass`, whereas, the second occurrence will have `type=poison`.<jupyter_code>pkmn_types = pokemon.melt(id_vars = ['id','species'], 
                          value_vars = ['type_1', 'type_2'], 
                          var_name = 'type_level', value_name = 'type').dropna()
pkmn_types.head()
# YOUR CODE HERE
pk_order = pkmn_types['type'].value_counts().index
sb.countplot(y=pkmn_types['type'],color=base_color,order = pk_order)<jupyter_output><empty_output><jupyter_text>2. Your task is to use this dataframe to create a _relative frequency_ plot of the proportion of Pokémon with each type, _sorted_ from most frequent to least. **Hint**: The sum across bars should be greater than 100%, since many Pokémon have two types. Keep this in mind when considering a denominator to compute relative frequencies.<jupyter_code># YOUR CODE HERE
#pkmn_types.shape[0]
n_pokemon = pkmn_types['type'].value_counts().sum()
max_type = pkmn_types['type'].value_counts()[0]
max_type_pro = max_type / n_pokemon

tick_props = np.arange(0, max_type_pro, 0.02)
tick_names = ['{:.2f}'.format(v) for v in tick_props]
sb.countplot(y=pkmn_types['type'], color=base_color, order = pk_order);
plt.xticks(tick_props * n_pokemon, tick_names);<jupyter_output><empty_output><jupyter_text>Expected Output: TO DO Task 2<jupyter_code># The function below has been defined in the `solutions_univ.py` file, that you can refer only when necessary. 
# This function contains the expected solution. 
bar_chart_solution_2()<jupyter_output>I created a horizontal bar chart since there are a lot of Pokemon types. The unique() method was used to get the number of different Pokemon species. I also added an xlabel call to make sure it was clear the bar length represents a relative frequency.


The frequency of each type is:
 type_1    807
type_2    405
Name: type_level, dtype: int64
{'fraction_non_alphanumeric': 0.08003048780487805, 'fraction_numerical': 0.009527439024390244, 'mean_word_length': 5.401219512195122, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '190866', 'license': 'MIT', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1513, 'n_words': 645, 'path': 'Matplotlib/Bar_Chart_Practice_course.ipynb', 'repo_name': 'feng27/AIPND', 'size': '5248'}