4.10. general_functions module

general_functions.inputs_filenames(input_files_pathlist)[source]
Parameters:

input_files_pathlist: List; those input files that are specified in the Input_Files.csv file contained in the inputs folder.

Returns:

A list of input file full paths - these will be copied directly to the output folder so that inputs and outputs end up bundled together in the output folder associated with the given run.

general_functions.reshape_df(df, value_variable_list, cols_to_melt, melted_header, new_column_name)[source]
Parameters:

df: The DataFrame to melt.

value_variable_list: Column(s) list to use as identifier variables.

cols_to_melt: Column(s) list of columns to pivot (melt).

melted_header: The header for the column to be populated with the cols_to_melt list.

new_column_name: Name to use for the ‘Value’ column.

Returns:

A new DataFrame in long and narrow shape rather than the passed short and wide shape.

Note:

This function is not being used.

general_functions.convert_dollars_to_analysis_basis(df, deflators, dollar_basis, *args)[source]

This function converts dollars into a consistent dollar basis as set via the General Inputs file.

Parameters:

df: DataFrame; contains the monetized values and their associated input cost basis.

deflators: Dictionary; provides GDP deflators for use in adjusting monetized values throughout the tool into a consistent dollar basis.

dollar_basis: Numeric; the dollar basis to be used throughout the analysis as set via the General Inputs file.

args: String(s); the attributes within the passed df to be adjusted into ‘dollar_basis’ dollars.

Returns:

The passed DataFrame will all args adjusted into dollar_basis dollars.

general_functions.round_metrics(df, metrics, round_by)[source]
Parameters:

df: DataFrame containing data to be rounded.

metrics: List of metrics within the passed DataFrame for which rounding is requested.

round_by: A value that sets the level of rounding.

Returns:

The passed DataFrame with ‘metrics’ rounded by ‘round_by’.

Note:

This function is not being used.

general_functions.round_sig(df, divisor=1, sig=0, *args)[source]
Parameters:

df: The DataFrame containing data to be expressed in ‘sig’ significant digits.

divisor: The divisor to use in calculating results.

sig: The number of significant digits to use for results.

args: The arguments to be expressed in ‘sig’ significant digits and in ‘divisor’ units.

Returns:

The passed DataFrame with args expressed in ‘sig’ significant digits and in ‘divisor’ units.

Note:

This function is not being used.

general_functions.get_file_datetime(list_of_files)[source]
Parameters:

list_of_files: List; the files for which datetimes are required.

Returns:

A DataFrame of input files (full path) and corresponding datetimes (date stamps) for those files.

general_functions.read_input_files(path, input_file, usecols=None, index_col=None, skiprows=None, reset_index=False)[source]
Parameters:

path: String; the path to input files.

input_file: String; the file (filename) to read.

usecols: List; the columns to used in the returned DataFrame.

index_col: Numeric; the column to use as the index column of the returned DataFrame.

skiprows: Numeric; the number of rows to skip when reading the file.

reset_index: Boolean; True resets index, False does not.

Returns:

A DataFrame of the desired data from the passed input file.

general_functions.get_common_metrics(df_left, df_right, ignore=None)[source]

This function simply finds common metrics between 2 DataFrames being merged to ensure a safe merge.

Parameters:

df_left: The left DataFrame being merged.

df_right: The right DataFrame being merged.

ignore: Any columns (arguments) to ignore when finding common metrics.

Returns:

A DataFrame merged on the common arguments (less any ignored arguments).

Note:

This function is not being used.

general_functions.save_dict_to_csv(dict_to_save, save_path, row_header=None, *args)[source]
Parameters:

dict_to_save: Dictionary; a dictionary having a tuple of args as keys.

save_path: Path object; the path for saving the passed CSV.

row_header: List; the column names to use as the row header for the preferred structure of the output file. args: String(s); the attributes contained in the tuple key - these will be pulled out and named according to the passed arguments.

Returns:

A CSV file with individual key elements split out into columns with args as names.