surveys.py
| FUNCTION | DESCRIPTION |
|---|---|
validate |
Validate a survey DataFrame for required columns and acceptable value ranges. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
ATTRIBUTES_COLUMN_NAMES |
List of allowed column names for survey data.
|
ATTRIBUTES_VALUES |
Allowed inclusive range for attribute values.
|
ATTRIBUTES_COLUMN_NAMES
module-attribute
ATTRIBUTES_COLUMN_NAMES = ['pleasant', 'present', 'light', 'engaging', 'unpleasant', 'absent', 'overpowering', 'detached']
List of allowed column names for survey data. The survey DataFrame must include these columns.
ATTRIBUTES_VALUES
module-attribute
ATTRIBUTES_VALUES = [1, 2, 3, 4, 5]
Allowed inclusive range for attribute values. Values can range from 1 (minimum) to 5 (maximum).
validate
validate(df)
Validate a survey DataFrame for required columns and acceptable value ranges.
This function ensures that the provided DataFrame contains all necessary
survey and ID columns, and that all numeric responses fall within the
defined set ATTRIBUTES_VALUES.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
A DataFrame containing survey data. Must include columns listed in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
df
|
A DataFrame containing only valid rows with complete data.
TYPE:
|
excl_df
|
A DataFrame containing rows removed due to missing values.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception "Missing mandatory column/s"
|
If any required columns are missing |
Exception "Attribute values are not valid"
|
If any numeric responses fall outside the allowed range. |
Examples:
>>> import pandas as pd
>>> from smellscapy.databases.DataExample import load_example_data
>>> from smellscapy.surveys import validate
>>> df = load_example_data()
>>> df, excl_df = validate(df) # passes without error
Source code in src/smellscapy/surveys.py
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |