pshelpers module¶
-
tripsender.pshelpers.
clean_travel_data
(travelData)¶ A function that cleans the raw travel data from the travel survey
csv
.- Parameters
travelData – (Pandas DataFrame) A DataFrame containing raw data from the Swedish Travel Survey
- Returns
(Pandas DataFrame) A cleaned DataFrame containing data from the Swedish Travel Survey
-
tripsender.pshelpers.
create_persona
(df_Personas, write=True)¶ A function to create personas from a list of
Pandas DataFrame
containing data from the Swedish Travel Survey.- Parameters
df_Personas – (list) List of Pandas DataFrame containing data from the Swedish Travel Survey
write – (bool: Optional) If True, write to path ‘data/dict’ as json
- Returns
(list) A list of dictionaries containing data from the Swedish Travel Survey
-
tripsender.pshelpers.
get_mode
(randomPersona, key)¶ A function to get the mode of travel from and individual dict containing a persona.
- Parameters
randomPersona – (dict) A dict containing one persona
key – (str) A valid tripID within the random persona to get the mode of travel from
- Returns
(int,int) Mode index and mode speed. (0 = walk, 1 = bike, 2 = e-bike … see RVU documentation for details)
-
tripsender.pshelpers.
get_random_persona
(age, gender, dict_Personas)¶ A function to fetch a random persona from a list of dictionaries, given the required age and gender. Male is 1 and Female is 2.
- Parameters
age – (int)
gender – (int) 1 for Male and 2 for Female
dict_Personas – (list) An ordered list of 14 dicts for each age group and gender
- Returns
(dict) A randomly fetched persona from the Swedish Travel Survey as a dictionary
-
tripsender.pshelpers.
retrieve_name
(var)¶ A utility function to retrieve the variable name from a named python element.
- Parameters
var – (python variable element)
- Returns
(str) The name of the variable element supplied
-
tripsender.pshelpers.
split_travel_data
(travelData)¶ A function that takes a list of
Pandas DataFrame
representing the travel data for each age group and gender.- Parameters
travelData – (Pandas DataFrame) A combined DataFrame with all travel data
- Returns
(list) A list of cleaned DataFrame split from the combined DataFrame
-
tripsender.pshelpers.
travel_json_to_english
(swedish_json)¶ A function to replace the Swedish keys with English keys on the travel data
JSON
.- Parameters
swedish_json – (JSON object) The original JSON from the Swedish Travel Survey
- Returns
(dict) The replaced data as dict with English variable names