<jupyter_start><jupyter_text>Challenge 1In this challenge you will be working on **Pokemon**. You will answer a series of questions in order to practice dataframe calculation, aggregation, and transformation.![Pokemon](../images/pokemon.jpg)Follow the instructions below and enter your code. Import all required libraries.<jupyter_code># import libraries
import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Import data set.Import data set `Pokemon` from Ironhack's database. Read the data into a dataframe called `pokemon`.*Data set attributed to [<NAME>](https://www.kaggle.com/abcsds/pokemon/)*<jupyter_code># import data set from Ironhack's database
pokemon_dataset = pd.read_csv('C:/Users/aleja/daft-miami-1019-labs/module-1/Dataframe-Calculations/Pokemon.csv')
pokemon_dataset<jupyter_output><empty_output><jupyter_text>Print first 10 rows of `pokemon`.<jupyter_code># your code here
print(pokemon_dataset.head(10))<jupyter_output>#                       Name Type 1  Type 2  Total  HP  Attack  Defense  \
0  1                  Bulbasaur  Grass  Poison    318  45      49       49   
1  2                    Ivysaur  Grass  Poison    405  60      62       63   
2  3                   Venusaur  Grass  Poison    525  80      82       83   
3  3      VenusaurMega Venusaur  Grass  Poison    625  80     100      123   
4  4                 Charmander   Fire     NaN    309  39      52       43   
5  5                 Charmeleon   Fire     NaN    405  58      64       58   
6  6                  Charizard   Fire  Flying    534  78      84       78   
7  6  CharizardMega Charizard X   Fire  Dragon    634  78     130      111   
8  6  CharizardMega Charizard Y   Fire  Flying    634  78     104       78   
9  7                   Squirtle  Water     NaN    314  44      48       65   

   Sp. Atk  Sp. Def  Speed  Generation  Legendary  
0       65       65     45           1      False  
1       80       80     60           [...]<jupyter_text>When you look at a data set, you often wonder what each column means. Some open-source data sets provide descriptions of the data set. In many cases, data descriptions are extremely useful for data analysts to perform work efficiently and successfully.For the `Pokemon.csv` data set, fortunately, the owner provided descriptions which you can see [here](https://www.kaggle.com/abcsds/pokemon/home). For your convenience, we are including the descriptions below. Read the descriptions and understand what each column means. This knowledge is helpful in your work with the data.| Column | Description || --- | --- ||  | ID for each pokemon || Name | Name of each pokemon || Type 1 | Each pokemon has a type, this determines weakness/resistance to attacks || Type 2 | Some pokemon are dual type and have 2 || Total | A general guide to how strong a pokemon is || HP | Hit points, or health, defines how much damage a pokemon can withstand before fainting || Attack | The base modifier for normal attacks (eg. Scratch, Punch) || Defense | The base damage resistance against normal attacks || SP Atk | Special attack, the base modifier for special attacks (e.g. fire blast, bubble beam) || SP Def | The base damage resistance against special attacks || Speed | Determines which pokemon attacks first each round || Generation | Number of generation || Legendary | True if Legendary Pokemon False if not |  Obtain the distinct values across `Type 1` and `Type 2`.Exctract all the values in `Type 1` and `Type 2`. Then create an array containing the distinct values across both fields.<jupyter_code># your code here
Types1and2 = np.array(pokemon_dataset['Type 1'], pokemon_dataset['Type 2'])
Types1and2 = np.unique(Types1and2)
Types1and2<jupyter_output><empty_output><jupyter_text>Cleanup `Name` that contain "Mega".If you have checked out the pokemon names carefully enough, you should have found there are junk texts in the pokemon names which contain "Mega". We want to clean up the pokemon names. For instance, "VenusaurMega Venusaur" should be "Mega Venusaur", and "CharizardMega Charizard X" should be "Mega Charizard X".<jupyter_code># your code here

#x = np.where(pokemon_dataset['Name'].str.contains('Mega'),"Mega", pokemon_dataset['Name'])
def mega_deleter(x):
    x = x.lower()
    if "mega" in x:
        x = x.split()[-1]
    return x
pokemon_dataset['Name'].apply(mega_deleter)
# test transformed data
#pokemon_dataset['Name'].head(10)[3]<jupyter_output><empty_output><jupyter_text>Create a new column called `A/D Ratio` whose value equals to `Attack` devided by `Defense`.For instance, if a pokemon has the Attack score 49 and Defense score 49, the corresponding `A/D Ratio` is 49/49=1.<jupyter_code># your code here
pokemon_dataset['A/D Ratio'] = pokemon_dataset['Attack']/pokemon_dataset['Defense']
pokemon_dataset.head()

type(pokemon_dataset['Type 2'][4])
pokemon_dataset['new'] = pokemon_dataset['Type 1'] + pokemon_dataset['Type 2']
pokemon_dataset['Type 2'].unique()
pokemon_dataset['Type 1'].unique()<jupyter_output><empty_output><jupyter_text>Identify the pokemon with the highest `A/D Ratio`.<jupyter_code># your code here
pokemon_dataset['A/D Ratio'].max()<jupyter_output><empty_output><jupyter_text>Identify the pokemon with the lowest A/D Ratio.<jupyter_code># your code here
pokemon_dataset['A/D Ratio'].min()<jupyter_output><empty_output><jupyter_text>Create a new column called `Combo Type` whose value combines `Type 1` and `Type 2`.Rules:* If both `Type 1` and `Type 2` have valid values, the `Combo Type` value should contain both values in the form of ` `. For example, if `Type 1` value is `Grass` and `Type 2` value is `Poison`, `Combo Type` will be `Grass-Poison`.* If `Type 1` has valid value but `Type 2` is not, `Combo Type` will be the same as `Type 1`. For example, if `Type 1` is `Fire` whereas `Type 2` is `NaN`, `Combo Type` will be `Fire`.<jupyter_code># your code here
pokemon_dataset = pokemon_dataset.drop(['new'], axis=1)
def fun(x,y):
    if type(x) == float and type(y) == str:
        return y
    elif type(y) == float and type(x) == str:
        return x
    elif  type(x) == str and  type(y) == str:
        return (x+'-'+y)
pokemon_dataset['Combo Type']=list(map(fun, pokemon_dataset['Type 1'], pokemon_dataset['Type 2']))
pokemon_dataset.head()<jupyter_output><empty_output><jupyter_text>Identify the pokemon whose `A/D Ratio` are among the top 5.<jupyter_code># your code here
pokemon_dataset.sort_values('A/D Ratio', ascending = False).head()['Name']<jupyter_output><empty_output><jupyter_text>For the 5 pokemon printed above, aggregate `Combo Type` and use a list to store the unique values.Your end product is a list containing the distinct `Combo Type` values of the 5 pokemon with the highest `A/D Ratio`.<jupyter_code># your code here
pokemon_dataset.sort_values('A/D Ratio', ascending = False).head(5)[['Name','A/D Ratio', 'Combo Type']]

list(pokemon_dataset.sort_values('A/D Ratio', ascending = False).head(5)['Combo Type'])<jupyter_output><empty_output><jupyter_text>For each of the `Combo Type` values obtained from the previous question, calculate the mean scores of all numeric fields across all pokemon.Your output should look like below:![Aggregate](../images/aggregated-mean.png)<jupyter_code># your code here
#pokemon_numeric = pokemon_dataset[['Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Generation', 'A/D Ratio']]
#pokemon_numeric['Total'] = pokemon_dataset['Total'].mean(axis=1)
?#pokemon_numeric.head()
temp = pokemon_dataset.sort_values('A/D Ratio', ascending = False).head(5)
result = temp.groupby('Combo Type')['Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def','Speed','Generation', 'A/D Ratio'].mean()
result
pokemon_dataset.sort_values('A/D Ratio', ascending = False).head(5)[['Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Generation', 'A/D Ratio']]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10743696946661599, 'fraction_numerical': 0.02533890789306981, 'mean_word_length': 3.936835522201376, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '461921', 'license': 'MIT', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2452, 'n_words': 880, 'path': 'module-1/Dataframe-Calculations/your-code/challenge-1.ipynb', 'repo_name': 'AlejandroPenaloza/daft-miami-1019-labs', 'size': '7903'}