<jupyter_start><jupyter_text>ExamDuring the exam we will analyze League of Legends match data. You will have 10 tasks to complete over `2` hours. You can use any resources you need (internet, notes, documentation), but you must complete the task alone - violation will be severly punished. To pass you need `60%` correct answers. You need to post the exam in your repository until `17:15`. If you post your answers after `17:15`, you won't be graded based on your repository notebook work and will receive a grade of `2`. Grading| Points | Grade || :-- | :-- || 6 | 3 || 7 | 3.5 || 8 | 4 || 9 | 4.5 || 10 | 5 |Each task can get between `0` and `1` points. So, if you do only a couple of things correct you can get eg. `0.6` points.<jupyter_code># Your student id here
student_id = 136302
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()<jupyter_output><empty_output><jupyter_text>Task 1`[0.4]` Import the csv file `high_diamond_ranked_10min.csv` to a variable `lol_data`. Set the index column to `gameId`.<jupyter_code>lol_data = pd.read_csv(
    "high_diamond_ranked_10min.csv",
    index_col="gameId",
)<jupyter_output><empty_output><jupyter_text>`[0.2]` Display random 10 rows from the dataset.<jupyter_code>lol_data.sample(10)<jupyter_output><empty_output><jupyter_text>`[0.2]` Display the information about the dataset - columns, dtypes, etc.<jupyter_code>lol_data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 9879 entries, 4519157822 to 4523772935
Data columns (total 39 columns):
 #   Column                        Non-Null Count  Dtype  
---  ------                        --------------  -----  
 0   blueWins                      9879 non-null   int64  
 1   blueWardsPlaced               9879 non-null   int64  
 2   blueWardsDestroyed            9879 non-null   int64  
 3   blueFirstBlood                9879 non-null   int64  
 4   blueKills                     9879 non-null   int64  
 5   blueDeaths                    9879 non-null   int64  
 6   blueAssists                   9879 non-null   int64  
 7   blueEliteMonsters             9879 non-null   int64  
 8   blueDragons                   9879 non-null   int64  
 9   blueHeralds                   9879 non-null   int64  
 10  blueTowersDestroyed           9879 non-null   int64  
 11  blueTotalGold                 9879 non-null   int64  
 12  blueAvgLevel                  9879 non-null   f[...]<jupyter_text>`[0.2]` Display statistical information about the dataset - mean, quartiles, etc.<jupyter_code>lol_data.describe()<jupyter_output><empty_output><jupyter_text>Task 2`[0.2]` Create a new column `whoWon` which contains `"red"` or `"blue"` based on the `blueWins` column.<jupyter_code>lol_data['whoWon'] = lol_data['blueWins'].map(lambda b: "red" if b == 0 else "blue")
lol_data.sample(5)<jupyter_output><empty_output><jupyter_text>`[0.2]` Create a new column `firstKill` which contains `"red"` or `"blue"` based on either `blueFirstBlood` or `redFirstBlood`.<jupyter_code>lol_data['firstKill'] = lol_data['blueFirstBlood'].map(lambda b: "blue" if b == 1 else "red")
lol_data.sample(5)<jupyter_output><empty_output><jupyter_text>`[0.1]` Set the dtype of the `whoWon` and `firstKill` to categorical.<jupyter_code>lol_data['whoWon'].astype('category')
lol_data['firstKill'].astype('category')<jupyter_output><empty_output><jupyter_text>`[0.5]` Cast all `float` columns to `int`, while setting each value to its ceiling.<jupyter_code>for (name, values) in lol_data.iteritems():
    if values.dtype == float:
        lol_data[name] = values.map(lambda v: int(v + 1) if int(v) < v else int(v)) 
        
lol_data.sample(5)<jupyter_output><empty_output><jupyter_text>Task 3`[1.0]` Create two new columns: `blueFinalWards` and `redFinalWards` that are calculated in the following manner:```blueFinalWards = blueWardsPlaced - redWardsDestroyedredFinalWards = redWardsPlaced - blueWardsDestroyed```<jupyter_code>def get_bfw(row):
    row['blueFinalWards'] = row['blueWardsPlaced'] - row['redWardsDestroyed'] 
    return row

def get_rfw(row):
    row['redFinalWards'] = row['redWardsPlaced'] - row['blueWardsDestroyed'] 
    return row

lol_data = lol_data.apply(get_bfw, axis='columns')
lol_data = lol_data.apply(get_rfw, axis='columns')<jupyter_output><empty_output><jupyter_text>Task 4`[0.5]` Create two new columns: `blueMinionsKilledOutsideJungle` and `redMinionsKilledOutsideJungle` which is a difference of two specific columns in the dataset and save it to the variable `lol_data_updated`.<jupyter_code>def get_bminions(row):
    row['blueMinionsKilledOutsideJungle'] = row['blueTotalMinionsKilled'] - row['blueTotalJungleMinionsKilled'] 
    return row

def get_rminions(row):
    row['redMinionsKilledOutsideJungle'] = row['redTotalMinionsKilled'] - row['redTotalJungleMinionsKilled']
    return row

lol_data_updated = lol_data.apply(get_bminions, axis='columns')
lol_data_updated = lol_data_updated.apply(get_rminions, axis='columns')<jupyter_output><empty_output><jupyter_text>`[0.5]` Remove the following columns: `blueTotalMinionsKilled`, `redTotalMinionsKilled`, `blueTotalJungleMinionsKilled`, `redTotalJungleMinionsKilled` and save this to the previous variable.<jupyter_code>lol_data = lol_data_updated.drop(['blueTotalMinionsKilled', 'redTotalMinionsKilled', 'blueTotalJungleMinionsKilled', 'redTotalJungleMinionsKilled'], axis='columns')<jupyter_output><empty_output><jupyter_text>Task 5`[0.8]` Create a new variable `lol_data_group` where you groupby `whoWon` and `firstKill`, with the following aggregations:- `blueTotalGold` - sum- `redTotalGold` -  sum- `blueKills` - mean- `redKills` - mean- `blueGoldPerMin` - max- `redGoldPerMin` - min<jupyter_code>lol_data_group = lol_data.groupby(['whoWon', 'firstKill']).agg({'blueTotalGold': ['sum'], 'redTotalGold': ['sum'], 'blueKills': ['mean'], 'redKills': ['mean'], 'blueGoldPerMin': ['max'], 'redGoldPerMin': ['min']})

lol_data_group<jupyter_output><empty_output><jupyter_text>`[0.2]` **Rename** (use good function here) the columns of `lol_data_group` to `blueTotalGoldSum`, `redTotalGoldSum`, `blueKillsMean`, `redKillsMean`, `blueGoldPerMinMax`, `redGoldPerMinMin`.<jupyter_code>lol_data_group.columns = ['blueTotalGoldSum', 'redTotalGoldSum', 'blueKillsMean', 'redKillsMean', 'blueGoldPerMinMax', "redGoldPerMinMin"]

lol_data_group<jupyter_output><empty_output><jupyter_text>Task 6`[1.0]` Melt the DataFrame where the id variables are the index and value vars are `blueHeralds`, `redHeralds`, `blueDragons`, `redDragons`, `blueEliteMonsters` and `redEliteMonsters`. Save the result as `lol_data_melt`.*Hint: you can use `reset_index()` to achieve a correct melt.*<jupyter_code>lol_data_melt = pd.melt(lol_data.reset_index(), id_vars='gameId', value_vars=['blueHeralds', 'redHeralds', 'blueDragons', 'redDragons', 'blueEliteMonsters', 'redEliteMonsters'])

lol_data_melt<jupyter_output><empty_output><jupyter_text>Task 7`[1.0]` Create a seaborn `barplot` of the `lol_data_melt` where `x` is the variable, and `y` is the value.<jupyter_code>fig, axes = plt.subplots()
sns.barplot(
    x='variable',
    y='value',
    data=lol_data_melt,
)
fig.set_size_inches(10, 6)<jupyter_output><empty_output><jupyter_text>Task 8`[1.0]` Create a seaborn `scatterplot` of `lol_data`.- For `x` select `blueGoldPerMin`,- For `y` select `redGoldPerMin`, - Color the graph by `whoWon`,- Change dots to be different based on `firstKill` (dots and crosses).<jupyter_code>fig, axes = plt.subplots()
sns.scatterplot(
    x="blueGoldPerMin",
    y="redGoldPerMin",
    hue="whoWon",
    style="firstKill",
    marker="o",
    data=lol_data,
)
fig.set_size_inches(10, 6)<jupyter_output><empty_output><jupyter_text>Task 9`[0.5]` Create a horizontal `matplotlib` subplot that holds two distribution plots using seaborn for `lol_data`: `redCSPerMin` and `blueCSPerMin`.<jupyter_code>fig, axes = plt.subplots(1, 2)
sns.distplot(lol_data['redCSPerMin'], ax=axes[0])
sns.distplot(lol_data['blueCSPerMin'], ax=axes[1])
fig.set_size_inches(15, 6)<jupyter_output><empty_output><jupyter_text>`[0.5]` Create a seaborn `boxplot` using `lol_data` for the `blueAvgLevel` column depending on `whoWon`.<jupyter_code>sns.boxplot(
    x="whoWon",
    y="blueAvgLevel",
    data=lol_data,
)<jupyter_output><empty_output><jupyter_text>Task 10`[1.0]` Create a triangle (half square) seaborn `clustermap` of the `lol_data` correlations.- Change the color palette to "mako"*Hint: You can check stack overflow how to create masks using `numpy`.*<jupyter_code># Your code here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12736399719822555, 'fraction_numerical': 0.02720056035489143, 'mean_word_length': 5.016151685393258, 'pattern_counts': {'":': 0, '<': 82, '<?xml version=': 0, '>': 81, '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': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '655242', 'license': 'MIT', 'n_tokens_mistral': 3209, 'n_tokens_neox': 3010, 'n_words': 717, 'path': 'Exam/exam.ipynb', 'repo_name': 'Reynart01/introduction-to-python', 'size': '8566'}