text_html_output_1.png
from pandas.io.json import json_normalize

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

with open('../input/matches.txt') as file:
    CR = [x.strip() for x in file.readlines()]

deserialize_cr = [json_normalize(eval(r1)) for r1 in CR[0:10000]]
df_cr = pd.concat(deserialize_cr, ignore_index=True)
df_cr.columns = ['Left Clan', 'Left Deck', 'Left Player', 'Left Trophy', 'Right Clan', 'Right Deck', 'Right Player', 'right Trophy', 'Result', 'Time', 'Type']

Left_Troops = list(np.hstack([[x[0] for x in left_deck] for left_deck in df_cr['Left Deck']]))
Right_Troops = list(np.hstack([[x[0] for x in right_deck] for right_deck in df_cr['Right Deck']]))
distinct_troops = set(np.hstack([Left_Troops, Right_Troops]))
len(distinct_troops)

RightArmy_colNames = np.hstack([['Right Troop ' + str(i + 1) for i in range(8)], ['Right Troop Count ' + str(i + 1) for i in range(8)]])
LeftArmy_colNames = np.hstack([['Left Troop ' + str(i + 1) for i in range(8)], ['Left Troop Count ' + str(i + 1) for i in range(8)]])
RightArmy = pd.DataFrame(data=[np.hstack([[army[0] for army in x], [army[1] for army in x]]) for x in df_cr['Right Deck']], columns=RightArmy_colNames)
LeftArmy = pd.DataFrame(data=[np.hstack([[army[0] for army in x], [army[1] for army in x]]) for x in df_cr['Left Deck']], columns=LeftArmy_colNames)
finalCR_data = pd.concat([df_cr, LeftArmy, RightArmy], axis=1, join='inner')
finalCR_data.head()