Пример #1
0
def q06_battles_on_each_region(battles):
    'write your solution here'
    battles1, character_predictions1 = q01_feature_engineering(
        battles, character_predictions)
    df = battles1.groupby('region').sum()[['major_death', 'major_capture']]
    df1 = battles1.region.value_counts()
    df1 = df1.to_frame()
    df1 = df1.sort_values('region', ascending=False)
    df1.columns = ['No.of battles']
    df2 = pd.concat([df, df1], axis=1)
    c = df2.plot.bar()
    c.set(xlabel='region', ylabel='No.of events')
    return df
# %load q08_preprocessing/build.py
import pandas as pd
import numpy as np
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.curdir)))
from greyatomlib.game_of_thrones.q01_feature_engineering.build import q01_feature_engineering
from greyatomlib.game_of_thrones.q07_culture_survival.build import q07_culture_survival

battles = pd.read_csv('data/battles.csv')
character_predictions = pd.read_csv('data/character-predictions.csv')

battle, character_pred = q01_feature_engineering(battles,
                                                 character_predictions)


def q08_preprocessing(data):
    #'write your solution here'
    colu = ['title', 'culture', 'mother', 'father', 'house', 'heir', 'spouse']
    for col in colu:
        data[col] = pd.factorize(data[col])[0]
    col_1 = ['name', 'alive', 'pred', 'plod', 'isAlive', 'dateOfBirth']
    data = data.drop(col_1, 1)
    col = data.columns
    for c in col:
        data[c] = data[c].replace(['.', '_'], ' ')
    for c in col:
        data[c] = data[c].replace(np.nan, -1)

    return (data)

Пример #3
0
def q03_eda_major_houses_on_attacking_side(battle):
    'write your solution here'
    battles1,character_predictions1 = q01_feature_engineering(battles,character_predictions)

    a = battles1.attacker_count.value_counts().sort_index().plot.bar()
    a.set(xlabel = 'No. of Major Attacker Houses', ylabel = 'Count')