CCC utility functions
Contents
CCC utility functions¶
utils
ccc.utils¶
- ccc.utils.diff_two_tables(df1, df2)[source]¶
Create the difference between two dataframes.
- Parameters
df1 (Pandas DataFrame) – first DataFrame in difference
df2 (Pandas DataFrame) – second DataFrame in difference
- Returns
- DataFrame with differences between
two DataFrames
- Return type
diff_df (Pandas DataFrame)
- ccc.utils.json_to_dict(json_text)[source]¶
Convert specified JSON text into an ordered Python dictionary.
- Parameters
json_text (string) – JSON text
- Raises
ValueError – if json_text contains a JSON syntax error
- Returns
- JSON data expressed as
an ordered Python dictionary.
- Return type
ordered_dict (collections.OrderedDict)
- ccc.utils.read_egg_csv(fname, index_col=None)[source]¶
Read from egg the file named fname that contains CSV data and return pandas DataFrame containing the data.
- Parameters
fname (string) – name of csv file
index_col (string) – name of column containing index
- Returns
data from csv file
- Return type
vdf (Pandas DataFrame)
- ccc.utils.read_egg_json(fname)[source]¶
Read from egg the file named fname that contains JSON data and return dictionary containing the data.
- Parameters
fname (string) – name of JSON file
- Returns
data from JSON file
- Return type
pdict (dict)
- ccc.utils.save_return_table(table_df, output_type=None, path=None, precision=0)[source]¶
Function to save or return a table of data.
- Parameters
table_df (Pandas DataFrame) – table
output_type (string) – specifies the type of file to save table to: ‘csv’, ‘tex’, ‘excel’, ‘json’
path (string) – specifies path to save file with table to
precision (integer) – number of significant digits to print. Defaults to 0.
- Returns
table
- Return type
table_df (Pandas DataFrame)
- ccc.utils.str_modified(i)[source]¶
Function to deal with conversion of a decimal number to a string.
- Parameters
i (scalar) – number that will convert to string
- Returns
number converted to a string
- Return type
str_i (string)
- ccc.utils.to_str(x)[source]¶
Function to decode string.
- Parameters
x (string) – string to decode
- Returns
decoded string
- Return type
x (string)
- ccc.utils.wavg(group, avg_name, weight_name)[source]¶
Computes a weighted average.
- Parameters
group (Pandas DataFrame) – data for the particular grouping
avg_name (string) – name of variable to compute wgt avg with
weight_name (string) – name of weighting variables
- Returns
weighted avg for the group
- Return type
d (scalar)