Module trase.tools.sei_pcs.reporting

Some useful functions to summarise Pandas dataframes

Functions

def print_report_by_attribute(df, value_column, by, significant_digits=2, printer=<built-in function print>)

Prints a summary of a dataframe when consolidated over one or more categorical columns. The absolute numbers are included as well as a relative percentage.

Example

>>> print_report_by_attribute(df, "vol", ["exporter"])
                     sum percentage
exporter
BUNGE      4,300,000,000        56%
ADM        2,200,000,000        28%
CARGILL    1,300,000,000        16%

Args

value_column
the numerical column to add up. Only one column is supported
by
the categorical column(s) to group over.
significant_digits
number of significant digits to round the numbers to, or None if you do not want rounding to occur (default: 2).
printer
a function which prints to the screen (default: print).
def report_percentage_by_attribute(df, value_column, by) ‑> pandas.core.frame.DataFrame