File size: 1,511 Bytes
c0f084a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
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