""" File: utils.py Author: Elena Ryumina and Dmitry Ryumin Description: Utility functions. License: MIT License """ import pandas as pd def preprocess_scores_df(df, name): df.index.name = name df.index += 1 df.index = df.index.map(str) return df def read_csv_file(file_path, drop_columns=[]): df = pd.read_csv(file_path) if len(drop_columns) != 0: df = pd.DataFrame(df.drop(drop_columns, axis=1)) return preprocess_scores_df(df, "ID") def round_numeric_values(x): if isinstance(x, (int, float)): return round(x, 3) return x def apply_rounding_and_rename_columns(df): df_rounded = df.rename( columns={ "Openness": "OPE", "Conscientiousness": "CON", "Extraversion": "EXT", "Agreeableness": "AGR", "Non-Neuroticism": "NNEU", } ) columns_to_round = df_rounded.columns[1:] df_rounded[columns_to_round] = df_rounded[columns_to_round].applymap( round_numeric_values ) return df_rounded def extract_profession_weights(df, dropdown_candidates): try: weights_professions = df.loc[df["Profession"] == dropdown_candidates, :].values[ 0 ][1:] interactive_professions = False except Exception: weights_professions = [0] * 5 interactive_professions = True else: weights_professions = list(map(int, weights_professions)) return weights_professions, interactive_professions