prettypandas.summarize module¶
-
class
prettypandas.summarizer.
Aggregate
(title, func, subset=None, axis=0, *args, **kwargs)¶ Bases:
object
Aggreagte
Wrapper to calculate aggregate row on datafame.
Parameters: - title – Aggregate row title
- func – Function to be passed to DataFrame.agg
- subset – Subset of DataFrame to compute aggregate on
- axis – Pandas axis to compute over
- args – Positionsal arguments to DataFrame.agg
- kwargs – Keyword arguments to DataFrame.agg
-
apply
(df)¶ Compute aggregate over DataFrame
-
class
prettypandas.summarizer.
Formatter
(formatter, args, kwargs)¶ Bases:
object
Wrapper to apply formatting to datafame.
Parameters: - formatter – Function to be passed to Pandas Styler.format
- args – Positionsal arguments to Styler.format
- kwargs – Keyword arguments to Styler.format
-
apply
(styler)¶ Apply Summary over Pandas Styler
-
class
prettypandas.summarizer.
PrettyPandas
(data, summary_rows=None, summary_cols=None, formatters=None, *args, **kwargs)¶ Bases:
object
Parameters: - data – DataFrame.
- summary_rows – list of Aggregate objects to be appended as a summary.
- summary_cols – list of Aggregate objects to be appended as a summary.
- formatters – List of Formatter objects to format.
-
as_currency
(currency=u'USD', locale=Locale('en_US'), *args, **kwargs)¶ Format subset as currency
Parameters: - currency – Currency
- locale – Babel locale for currency formatting
- subset – Pandas subset
-
as_percent
(precision=2, *args, **kwargs)¶ Format subset as percentages
Parameters: - precision – Decimal precision
- subset – Pandas subset
-
as_unit
(unit, location=u'suffix', *args, **kwargs)¶ Format subset as with units
Parameters: - unit – string to use as unit
- location – prefix or suffix
- subset – Pandas subset
-
average
(title=u'Average', **kwargs)¶ Add a mean summary to this table.
Parameters: title – Title to be displayed.
-
frame
¶ Add summaries and convert back to DataFrame
-
max
(title=u'Maximum', **kwargs)¶ Add a maximum summary to this table.
Parameters: title – Title to be displayed.
-
median
(title=u'Median', **kwargs)¶ Add a median summary to this table.
Parameters: title – Title to be displayed.
-
min
(title=u'Minimum', **kwargs)¶ Add a minimum summary to this table.
Parameters: title – Title to be displayed.
-
multi_summary
(funcs, titles, axis=0, *args, **kwargs)¶
-
render
()¶
-
style
¶ Add summaries and convert to Pandas Styler
-
summary
(func=<operator.methodcaller object>, title=u'Total', axis=0, subset=None, *args, **kwargs)¶ Add multiple summary rows or columns to the dataframe.
Parameters: - func – function to be used for a summary.
- titles – Title for this summary column.
- axis – Same as numpy and pandas axis argument. A value of None will cause the summary to be applied to both rows and columns.
- args – Positional arguments passed to all the functions.
- kwargs – Keyword arguments passed to all the functions.
The results of summary can be chained together.
-
to_frame
()¶ Add summaries and convert back to DataFrame
-
total
(title=u'Total', **kwargs)¶ Add a total summary to this table.
Parameters: title – Title to be displayed.