Add basic preprocessing functions

This commit is contained in:
coolneng 2020-12-31 01:56:54 +01:00
parent d656c32abe
commit 214b7093f0
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 29 additions and 0 deletions

29
src/preprocessing.py Normal file
View File

@ -0,0 +1,29 @@
from pandas import DataFrame, read_csv
from sklearn.preprocessing import normalize
from sklearn.model_selection import KFold
def replace_values(df) -> DataFrame:
for column in df.columns:
df[column].fillna(value=df[column].mean(), inplace=True)
return df
def remove_letters(df) -> DataFrame:
columns = ["Consumo", "Motor_CC", "Potencia"]
processed_df = df.copy()
for col in columns:
processed_df[col] = df[col].str.replace(pat="[^.0-9]", repl="").astype(float)
return processed_df
def split_k_sets(df):
k_fold = KFold(shuffle=True, random_state=42)
return k_fold.split(df)
def parse_data(source) -> DataFrame:
df = read_csv(filepath_or_buffer=source, na_values="?")
processed_df = df.dropna()
numeric_df = remove_letters(processed_df)
return numeric_df