# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import pandas as pd

# Read in csv but add in column names
df = pd.read_csv('../datasets/german.csv', sep='\s+', index_col = False, names=['Account Balance','Duration of Credit (month)','Payment Status of Previous Credit','Purpose',
                 'Credit Amount', 'Value Savings/Stocks', 'Length of current employment','Instalment per cent','Sex & Marital Status',
                 'Guarantors','Duration in Current address','Most valuable available asset','Age (years)','Concurrent Credits','Type of apartment','No of Credits at this Bank','Occupation','No of dependents',
                 'Telephone','Foreign Worker', 'Creditability'])
# Encoding Categorical Vairable
def encoding_category(accountBalance):
       return int(accountBalance[-1])

categorical_columns = [1,3,4,6,7,9,10,12,14,15,17,19,20]
for i in categorical_columns:
       df.iloc[:, i - 1] = df.iloc[:, i - 1].apply(lambda x: encoding_category(x))
# Encode Credibility
def encoding_credit(credibility):
       return credibility - 1
df['Creditability'] = df['Creditability'].apply(lambda x: encoding_credit(x))
# Write to a new file
df.to_csv('../datasets/german_cleaned.csv', index=False)

