SurveyVariable#

class tangles.convenience.SurveyVariable(name: str, var_type: str = 'unknown', label: str | None = None, valid_values: dict | None = None, invalid_values: dict | None = None, is_usable: bool = False)#

A variable (column) of a Survey.

Parameters#

namestr

The name of the variable.

var_typestr

The type of the variable.

labelstr

The label of the variable (often the question text or some brief version of it).

valid_valuesdict

A dictionary containing the possible ‘raw’ valid values as keys and (possibly meaningful) labels as values.

invalid_valuesdict

A dictionary containing the possible ‘raw’ invalid values as keys and (possibly meaningful) labels as values.

is_usablebool

A flag that is True, if we are sure that we can automatically create nice features for this question.

Methods

add_values()

Add valid_values and invalid_values to this survey variable’s valid and invalid values, respectively

all_values_as_list()

Return all (raw) values as a list

create_values()

Create a SurveyVariableValues object for this variable

invalid_values_as_list()

Return the (raw) invalid values as a list

is_nominal_type()

Check if this variable is nominal

is_numeric_type()

Check if this variable is numeric

is_ordinal_type()

Check if this variable is ordinal

is_valid_type()

Check the validity of this variable’s type string

is_valid_type_name()

A static function that checks if a string is a valid variable typename

replace_values()

Replace values by other values

set_value_labels()

Replace value labels by other labels, if the corresponding values are in the mapping

set_values()

Set this survey variable’s valid and invalid values

to_row()

Return the information contained in this object as a row

valid_values_as_list()

Return the (raw) valid values as a list

value_class()

Return the SurveyVariableValues subclass that this variable is an instance of