import pandas as pd
from functools import reduce

source_csv = 'data\\Kontenrahmen_Import.csv'
target_csv = 'data\\Kontenrahmen.csv'
result_csv = 'data\\Kontenrahmen_Ergebnis.csv'

debug = False
cols_pkey = ['Konto_Nr']


def update(d, other):
    d.update(dict(dict(other)))
    return d


def get_dict(cols, type):
    return dict(dict(zip(cols, [type] * len(cols))))

# cols_dict = reduce(update, (get_dict(cols_pkey, np.str), get_dict(cols_str, np.str), get_dict(cols_float, np.float)), {})


df_source = pd.read_csv(source_csv, decimal=",", sep=";", encoding="ansi", converters={i: str for i in range(0, 200)})
df_source['pkey'] = reduce(lambda x, y: x + "_" + df_source[y], cols_pkey, "")
df_source = df_source.set_index('pkey')

df_target = pd.read_csv(target_csv, decimal=",", sep=";", encoding="ansi", converters={i: str for i in range(0, 200)})
target_columns = df_target.columns
df_target['pkey'] = reduce(lambda x, y: x + "_" + df_target[y], cols_pkey, "")
df_target = df_target.set_index('pkey')

df_join = df_source.join(df_target, rsuffix='_other')[target_columns]
# df_result = df_join[(df_join['Gesamt'] != 0) & (df_join['Serviceberater'] != "")]

df_join.to_csv(result_csv, decimal=",", sep=";", encoding="ansi", index=None)
