import csv
import math

def count_group(database, title):
    print(title.upper()+"------------------------------------")
    vector_group = {}
    for count in database[title]:
        if(count in vector_group):
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count)+": "+str(vector_group[count]))

def isfloat(value):
    try:
        float(value)
        return True
    except ValueError:
        return False

database = {'age':[], 'job':[], 'marital':[], 'education':[], 'default':[], 'housing':[], 'loan':[], 'contact':[], 'month':[], 'day_of_week':[], 'duration':[], 'campaign':[], 'pdays':[], 'previous':[], 'poutcome':[], 'emp.var.rate':[], 'cons.price.idx':[], 'cons.conf.idx':[], 'euribor3m':[], 'nr.employed':[], 'y':[]}
#database = {'age':[], 'job':[], 'marital':[], 'education':[], 'housing':[], 'loan':[], 'contact':[], 'month':[], 'day_of_week':[], 'duration':[], 'campaign':[], 'pdays':[], 'previous':[], 'poutcome':[], 'emp.var.rate':[], 'cons.price.idx':[], 'cons.conf.idx':[], 'euribor3m':[], 'nr.employed':[], 'y':[]}

vector = []
empty_attributes = {}
empty_lines = []

with open('../data/raw_data.csv') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
    count = 0
    count2 = 1
    for row in spamreader:
        if count == 0:
            for row2 in row:
                vector.append(row2)
                count = count + 1
        else:
            count = 0
            for row2 in row:

                '''
                if(count == 4):
                    continue
                '''

                # is integer
                if row2.isdigit():
                    database[vector[count]].append(int(row2))
                # is float
                elif isfloat(row2):
                    database[vector[count]].append(float(row2))
                # is string
                else:
                    if(row2 == "unknown"):
                        if(count2 not in empty_lines) and (count != 4):
                            empty_lines.append(count2)

                        if(str(count2) in empty_attributes):
                            empty_attributes[str(count2)] += 1
                        else:
                            empty_attributes[str(count2)] = 1
                    else:
                        database[vector[count]].append(row2)
                count = count + 1
        count2 = count2 + 1

def create_new_csv(lines, columns):
    with open('../data/raw_data.csv') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=";", quotechar='"')
        line_count = 1
        with open('bank_cleaned.csv', 'w') as csvfile2:
            wr = csv.writer(csvfile2, delimiter=',', quotechar='"')
            for row in spamreader:
                vector = []
                column_count = 0

                if(line_count in lines):
                    line_count += 1
                    continue
                else:
                    for column in row:
                        if(column_count in columns):
                            column_count += 1
                            continue
                        vector.append(column)
                        column_count += 1

                    wr.writerow(vector)
                    line_count += 1

create_new_csv(empty_lines,[4])

75bb6d87e20ad029f86365a24ec9e36492518278
<mask token>


def count_group(database, title):
    print(title.upper() + '------------------------------------')
    vector_group = {}
    for count in database[title]:
        if count in vector_group:
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count) + ': ' + str(vector_group[count]))


<mask token>

<mask token>


def count_group(database, title):
    print(title.upper() + '------------------------------------')
    vector_group = {}
    for count in database[title]:
        if count in vector_group:
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count) + ': ' + str(vector_group[count]))


def isfloat(value):
    try:
        float(value)
        return True
    except ValueError:
        return False


<mask token>


def create_new_csv(lines, columns):
    with open('../data/raw_data.csv') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
        line_count = 1
        with open('bank_cleaned.csv', 'w') as csvfile2:
            wr = csv.writer(csvfile2, delimiter=',', quotechar='"')
            for row in spamreader:
                vector = []
                column_count = 0
                if line_count in lines:
                    line_count += 1
                    continue
                else:
                    for column in row:
                        if column_count in columns:
                            column_count += 1
                            continue
                        vector.append(column)
                        column_count += 1
                    wr.writerow(vector)
                    line_count += 1


<mask token>

<mask token>


def count_group(database, title):
    print(title.upper() + '------------------------------------')
    vector_group = {}
    for count in database[title]:
        if count in vector_group:
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count) + ': ' + str(vector_group[count]))


def isfloat(value):
    try:
        float(value)
        return True
    except ValueError:
        return False


database = {'age': [], 'job': [], 'marital': [], 'education': [], 'default':
    [], 'housing': [], 'loan': [], 'contact': [], 'month': [],
    'day_of_week': [], 'duration': [], 'campaign': [], 'pdays': [],
    'previous': [], 'poutcome': [], 'emp.var.rate': [], 'cons.price.idx': [
    ], 'cons.conf.idx': [], 'euribor3m': [], 'nr.employed': [], 'y': []}
vector = []
empty_attributes = {}
empty_lines = []
with open('../data/raw_data.csv') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
    count = 0
    count2 = 1
    for row in spamreader:
        if count == 0:
            for row2 in row:
                vector.append(row2)
                count = count + 1
        else:
            count = 0
            for row2 in row:
                """
                if(count == 4):
                    continue
                """
                if row2.isdigit():
                    database[vector[count]].append(int(row2))
                elif isfloat(row2):
                    database[vector[count]].append(float(row2))
                elif row2 == 'unknown':
                    if count2 not in empty_lines and count != 4:
                        empty_lines.append(count2)
                    if str(count2) in empty_attributes:
                        empty_attributes[str(count2)] += 1
                    else:
                        empty_attributes[str(count2)] = 1
                else:
                    database[vector[count]].append(row2)
                count = count + 1
        count2 = count2 + 1


def create_new_csv(lines, columns):
    with open('../data/raw_data.csv') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
        line_count = 1
        with open('bank_cleaned.csv', 'w') as csvfile2:
            wr = csv.writer(csvfile2, delimiter=',', quotechar='"')
            for row in spamreader:
                vector = []
                column_count = 0
                if line_count in lines:
                    line_count += 1
                    continue
                else:
                    for column in row:
                        if column_count in columns:
                            column_count += 1
                            continue
                        vector.append(column)
                        column_count += 1
                    wr.writerow(vector)
                    line_count += 1


create_new_csv(empty_lines, [4])

import csv
import math


def count_group(database, title):
    print(title.upper() + '------------------------------------')
    vector_group = {}
    for count in database[title]:
        if count in vector_group:
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count) + ': ' + str(vector_group[count]))


def isfloat(value):
    try:
        float(value)
        return True
    except ValueError:
        return False


database = {'age': [], 'job': [], 'marital': [], 'education': [], 'default':
    [], 'housing': [], 'loan': [], 'contact': [], 'month': [],
    'day_of_week': [], 'duration': [], 'campaign': [], 'pdays': [],
    'previous': [], 'poutcome': [], 'emp.var.rate': [], 'cons.price.idx': [
    ], 'cons.conf.idx': [], 'euribor3m': [], 'nr.employed': [], 'y': []}
vector = []
empty_attributes = {}
empty_lines = []
with open('../data/raw_data.csv') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
    count = 0
    count2 = 1
    for row in spamreader:
        if count == 0:
            for row2 in row:
                vector.append(row2)
                count = count + 1
        else:
            count = 0
            for row2 in row:
                """
                if(count == 4):
                    continue
                """
                if row2.isdigit():
                    database[vector[count]].append(int(row2))
                elif isfloat(row2):
                    database[vector[count]].append(float(row2))
                elif row2 == 'unknown':
                    if count2 not in empty_lines and count != 4:
                        empty_lines.append(count2)
                    if str(count2) in empty_attributes:
                        empty_attributes[str(count2)] += 1
                    else:
                        empty_attributes[str(count2)] = 1
                else:
                    database[vector[count]].append(row2)
                count = count + 1
        count2 = count2 + 1


def create_new_csv(lines, columns):
    with open('../data/raw_data.csv') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
        line_count = 1
        with open('bank_cleaned.csv', 'w') as csvfile2:
            wr = csv.writer(csvfile2, delimiter=',', quotechar='"')
            for row in spamreader:
                vector = []
                column_count = 0
                if line_count in lines:
                    line_count += 1
                    continue
                else:
                    for column in row:
                        if column_count in columns:
                            column_count += 1
                            continue
                        vector.append(column)
                        column_count += 1
                    wr.writerow(vector)
                    line_count += 1


create_new_csv(empty_lines, [4])

import csv
import math

def count_group(database, title):
    print(title.upper()+"------------------------------------")
    vector_group = {}
    for count in database[title]:
        if(count in vector_group):
            vector_group[count] += 1
        else:
            vector_group[count] = 1
    for count in vector_group:
        print(str(count)+": "+str(vector_group[count]))

def isfloat(value):
    try:
        float(value)
        return True
    except ValueError:
        return False

database = {'age':[], 'job':[], 'marital':[], 'education':[], 'default':[], 'housing':[], 'loan':[], 'contact':[], 'month':[], 'day_of_week':[], 'duration':[], 'campaign':[], 'pdays':[], 'previous':[], 'poutcome':[], 'emp.var.rate':[], 'cons.price.idx':[], 'cons.conf.idx':[], 'euribor3m':[], 'nr.employed':[], 'y':[]}
#database = {'age':[], 'job':[], 'marital':[], 'education':[], 'housing':[], 'loan':[], 'contact':[], 'month':[], 'day_of_week':[], 'duration':[], 'campaign':[], 'pdays':[], 'previous':[], 'poutcome':[], 'emp.var.rate':[], 'cons.price.idx':[], 'cons.conf.idx':[], 'euribor3m':[], 'nr.employed':[], 'y':[]}

vector = []
empty_attributes = {}
empty_lines = []

with open('../data/raw_data.csv') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
    count = 0
    count2 = 1
    for row in spamreader:
        if count == 0:
            for row2 in row:
                vector.append(row2)
                count = count + 1
        else:
            count = 0
            for row2 in row:

                '''
                if(count == 4):
                    continue
                '''

                # is integer
                if row2.isdigit():
                    database[vector[count]].append(int(row2))
                # is float
                elif isfloat(row2):
                    database[vector[count]].append(float(row2))
                # is string
                else:
                    if(row2 == "unknown"):
                        if(count2 not in empty_lines) and (count != 4):
                            empty_lines.append(count2)

                        if(str(count2) in empty_attributes):
                            empty_attributes[str(count2)] += 1
                        else:
                            empty_attributes[str(count2)] = 1
                    else:
                        database[vector[count]].append(row2)
                count = count + 1
        count2 = count2 + 1

def create_new_csv(lines, columns):
    with open('../data/raw_data.csv') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=";", quotechar='"')
        line_count = 1
        with open('bank_cleaned.csv', 'w') as csvfile2:
            wr = csv.writer(csvfile2, delimiter=',', quotechar='"')
            for row in spamreader:
                vector = []
                column_count = 0

                if(line_count in lines):
                    line_count += 1
                    continue
                else:
                    for column in row:
                        if(column_count in columns):
                            column_count += 1
                            continue
                        vector.append(column)
                        column_count += 1

                    wr.writerow(vector)
                    line_count += 1

create_new_csv(empty_lines,[4])
