text_plain_output_1.png
import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
import cvxpy as cvx
import pylab as plt
import networkx as nx
def prepare_data(data, suffix):
    data = data.drop(data.columns[range(3, 8)], axis=1)
    data = data.drop(data.columns[range(0, 2)], axis=1)
    data = data.groupby('settlement_name_english').sum()
    data = data.add_suffix(suffix)
    return data
def join_data(x_data, y_data, x_title, y_title):
    M1 = x_data.shape[1]
    M2 = y_data.shape[1]
    n_votes_x = np.sum(x_data.values)
    n_votes_y = np.sum(y_data.values)
    data_joint = pd.merge(x_data, y_data, how='inner', left_index=True, right_index=True)
    x_data = data_joint[data_joint.columns[range(1, M1)]]
    y_data = data_joint[data_joint.columns[M1 + 1:]]
    retained_votes_x = np.int(100 * np.round(np.sum(x_data.values) / n_votes_x, 2))
    retained_votes_y = np.int(100 * np.round(np.sum(y_data.values) / n_votes_y, 2))
    x_data = x_data.div(x_data.sum(axis=1), axis=0)
    x_data = x_data.mul(y_data.sum(axis=1), axis=0)
    avg_growth_factor = np.int(100 * np.round(np.sum(x_data.values) / n_votes_x - 1, 2))
    return (x_data, y_data)

x_data = pd.read_csv('../input/results_by_booth_2013 - english - v2.csv', encoding='iso-8859-1')
y_data = pd.read_csv('../input/results_by_booth_2015 - english - v3.csv', encoding='iso-8859-1')
x_data = prepare_data(x_data, '_2013')
y_data = prepare_data(y_data, '_2015')
[x_data, y_data] = join_data(x_data, y_data, '2013', '2015')
M1 = x_data.shape[1]
M2 = y_data.shape[1]