adapt preprocessing to new title loading

This commit is contained in:
2021-04-26 18:29:00 +02:00
parent 2998717cb4
commit 5c0fce0384

View File

@@ -1,17 +1,30 @@
import pandas as pd
import os
title_file = "filename_to_titles.csv"
# Preprocess data
vote_counter = -1
data = pd.DataFrame()
name_column = 'Bezeichnung'
column_to_filename = {}
# Load filename to
filename_to_title_map = {}
with open(os.path.join("./de/csv/", title_file), 'r') as file:
for line in file.readlines():
filename, title = line.split(';', 2)
filename_to_title_map[filename] = title
vote_column_to_title = {}
voting_features = ['ja', 'nein', 'Enthaltung', 'ungültig']
for dirname, _, filenames in os.walk('./de/csv'):
for filename in filenames:
if filename != title_file:
vote_counter += 1
print(os.path.join(dirname, filename))
df = pd.read_csv(os.path.join(dirname, filename))
@@ -21,7 +34,7 @@ for dirname, _, filenames in os.walk('./de/csv'):
df[feature] *= i
vote_column_name = f'vote_{vote_counter}'
# Map column name of vote to filename -> allows retrieving what the vote was about
column_to_filename[vote_column_name] = filename
vote_column_to_title[vote_column_name] = filename_to_title_map[filename]
# add feature for the vote
df[vote_column_name] = df[voting_features].sum(axis=1)
@@ -33,5 +46,5 @@ for dirname, _, filenames in os.walk('./de/csv'):
# merge data with already loaded data
data = data.merge(df[[name_column, vote_column_name]], on=name_column)
print(column_to_filename)
print(vote_column_to_title)
print(data)