<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 = 136100
# Import libraries you will use here
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Set seaborn coloring
sns.set(
    palette="bright"
)<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># Your code here
lol_data = pd.read_csv("high_diamond_ranked_10min.csv",
        index_col="gameId"
        )
print(lol_data)<jupyter_output>blueWins  blueWardsPlaced  blueWardsDestroyed  blueFirstBlood  \
gameId                                                                      
4519157822         0               28                   2               1   
4523371949         0               12                   1               0   
4521474530         0               15                   0               0   
4524384067         0               43                   1               0   
4436033771         0               75                   4               0   
...              ...              ...                 ...             ...   
4527873286         1               17                   2               1   
4527797466         1               54                   0               0   
4527713716         0               23                   1               0   
4527628313         0               14                   4               1   
4523772935         1               18                   0               1   [...]<jupyter_text>`[0.2]` Display random 10 rows from the dataset.<jupyter_code># Your code here
lol_data.sample(10)<jupyter_output><empty_output><jupyter_text>`[0.2]` Display the information about the dataset - columns, dtypes, etc.<jupyter_code># Your code here
lol_data.dtypes<jupyter_output><empty_output><jupyter_text>`[0.2]` Display statistical information about the dataset - mean, quartiles, etc.<jupyter_code># Your code here4
quan =lol_data.quantile([1/4,2/4,3/4])
print(quan)
mean =lol_data.mean()
print(mean)<jupyter_output>blueWins  blueWardsPlaced  blueWardsDestroyed  blueFirstBlood  \
0.25       0.0             14.0                 1.0             0.0   
0.50       0.0             16.0                 3.0             1.0   
0.75       1.0             20.0                 4.0             1.0   

      blueKills  blueDeaths  blueAssists  blueEliteMonsters  blueDragons  \
0.25        4.0         4.0          4.0                0.0          0.0   
0.50        6.0         6.0          6.0                0.0          0.0   
0.75        8.0         8.0          9.0                1.0          1.0   

      blueHeralds  ...  redTowersDestroyed  redTotalGold  redAvgLevel  \
0.25          0.0  ...                 0.0       15427.5          6.8   
0.50          0.0  ...                 0.0       16378.0          7.0   
0.75          0.0  ...                 0.0       17418.5          7.2   

      redTotalExperience  redTotalMinionsKilled  redTotalJungleMinionsKilled  \
0.25             17209.5             [...]<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'] = 0

lol_data['whoWon'] = np.where(
    (lol_data['blueWins'] == 0),
    'red',
    lol_data['whoWon']
)
lol_data['whoWon'] = np.where(
    (lol_data['blueWins'] == 1),
    'blue',
    lol_data['whoWon']
)<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># Your code here
lol_data['firstKill'] = 0
lol_data['firstKill'] = np.where(
    (lol_data['blueFirstBlood'] == 1),
    'blue',
    lol_data['firstKill']
)
lol_data['firstKill'] = np.where(
    (lol_data['redFirstBlood'] == 1),
    'red',
    lol_data['firstKill']
)<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.  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>lol_data["blueFinalWards"] = lol_data.blueWardsPlaced - lol_data.redWardsDestroyed

lol_data["redFinalWards"] = lol_data.redWardsPlaced - lol_data.blueWardsDestroyed<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># Your code here
lol_data["blueMinionsKilledOutsideJungle"] = lol_data.blueTotalMinionsKilled - lol_data.blueTotalJungleMinionsKilled

lol_data["redMinionsKilledOutsideJungle"] = lol_data.redTotalMinionsKilled - lol_data.redTotalJungleMinionsKilled<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># Your code here
lol_data.drop(columns=['blueTotalMinionsKilled','redTotalMinionsKilled','blueTotalJungleMinionsKilled','redTotalJungleMinionsKilled'])<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># Your code here

#??? i guess i don't understand it?
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).blueTotalGold.sum()
print(lol_data_group)
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).redTotalGold.sum()
print(lol_data_group)
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).blueKills.mean()
print(lol_data_group)
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).redKills.mean()
print(lol_data_group)
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).blueGoldPerMin.max()
print(lol_data_group)
lol_data_group = lol_data.groupby(["whoWon","firstKill"]).redGoldPerMin.min()
print(lol_data_group)<jupyter_output>whoWon  firstKill
blue    blue         52052931
        red          32473220
red     blue         32616328
        red          45895158
Name: blueTotalGold, dtype: int64
whoWon  firstKill
blue    blue         46593556
        red          31667955
red     blue         33417347
        red          51216382
Name: redTotalGold, dtype: int64
whoWon  firstKill
blue    blue         7.682290
        red          6.462687
red     blue         5.949500
        red          4.641573
Name: blueKills, dtype: float64
whoWon  firstKill
blue    blue         4.689990
        red          5.832733
red     blue         6.503500
        red          7.556799
Name: redKills, dtype: float64
whoWon  firstKill
blue    blue         2370.1
        red          2327.8
red     blue         2105.5
        red          2088.7
Name: blueGoldPerMin, dtype: float64
whoWon  firstKill
blue    blue         1121.2
        red          1317.3
red     blue         1289.1
        red          1378.9
Name: redGoldPerMin, [...]<jupyter_text>`[0.2]` **Rename** (use good function here) the columns of `lol_data_group` to `blueTotalGoldSum`, `redTotalGoldSum`, `blueKillsMean`, `redKillsMean`, `blueGoldPerMinMax`, `redGoldPerMinMin`.<jupyter_code># Your code here
lol_data_group.rename(columns={"1":"blueTotalGoldSum"},{"2":"redTotalGoldSum"},{"3":"redTotalGoldSum"},{"4":"blueKillsMean"},{"5":"redKillsMean"},{""})<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, id_vars=['whoWon'], value_vars=['blueHeralds','redHeralds','blueDragons','redDragons','blueEliteMonsters','redEliteMonsters'])
lol_data_melt.reset_index()<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># Your code here
sns.barplot(
    x="redEliteMonsters",
    y="redHeralds"
    data=lol_data_melt
)<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># Your code here
sns.scatterplot(
    x="blueGoldPerMin",
    y="redGoldPerMin",
    hue="whoWon",
    data=lol_data
)<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>sns.countplot(
    y="redCSPerMin",
    order="blueCSPerMin",
    data=lol_data,
)<jupyter_output><empty_output><jupyter_text>`[0.5]` Create a seaborn `boxplot` using `lol_data` for the `blueAvgLevel` column depending on `whoWon`.<jupyter_code># Your code here<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
sns.clustermap(
    lol_data.corr(),
    cmap="mako",
    linewidths=.75
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10838541180859994, 'fraction_numerical': 0.052513758044958496, 'mean_word_length': 2.7621052631578946, 'pattern_counts': {'":': 5, '<': 74, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '378215', 'license': 'MIT', 'n_tokens_mistral': 3953, 'n_tokens_neox': 3619, 'n_words': 860, 'path': 'exam.ipynb', 'repo_name': 'KryPote/introduction-to-python', 'size': '10721'}