prettypandas package

class prettypandas.PrettyPandas(data, summary_rows=None, summary_cols=None, formatters=None, *args, **kwargs)

Bases: pandas.io.formats.style.Styler

Pretty pandas dataframe Styles.

Parameters:
  • data – Series or DataFrame
  • precision – int precision to round floats to, defaults to pd.options.display.precision
  • table_styles – list-like, default None list of {selector: (attr, value)} dicts. These values overwrite the default style.
  • uuid – str, default None a unique identifier to avoid CSS collisons; generated automatically
  • caption – str, default None caption to attach to the table
  • summary_rows – list of single-row dataframes to be appended as a summary
  • summary_cols – list of single-row dataframes to be appended as a summary
DEFAULT_BACKGROUND = u'#eee'
DEFAULT_BORDER_COLOUR = u'#c0c0c0'
DEFAULT_LOCALE = Locale('en_US')
HEADER_PROPERTIES = [(u'background', u'#eee'), (u'font-weight', u'500')]
STYLES = [{u'props': [(u'background', u'#eee'), (u'font-weight', u'500')], u'selector': u'th'}, {u'props': [(u'text-align', u'right'), (u'min-width', u'3em')], u'selector': u'td'}, {u'props': [(u'border-color', u'#c0c0c0')], u'selector': u'*'}]
SUMMARY_PROPERTIES = [(u'background', u'#eee'), (u'font-weight', u'500')]
as_currency(subset=None, currency=u'USD', locale=None)

Represent subset of dataframe as currency.

Parameters:
  • subset – Pandas slice to convert to percentages
  • currency – Currency or currency symbol to be used
  • locale – Locale to be used (e.g. ‘en_US’)
as_money(subset=None, precision=None, currency=u'$', location=u'prefix')

[DEPRECATED] Represent subset of dataframe as currency.

Parameters:
  • precision – int Number of decimal places to round to
  • subset – Pandas slice to convert to percentages
  • currency – Currency string
  • location – ‘prefix’ or ‘suffix’ indicating where the currency symbol should be.
as_percent(subset=None, precision=None, locale=None)

Represent subset of dataframe as percentages.

Parameters:
  • subset – Pandas slice to convert to percentages
  • precision – int Number of decimal places to round to
  • locale – Locale to be used (e.g. ‘en_US’)
as_unit(unit, subset=None, precision=None, location=u'prefix')

Represent subset of dataframe as a special unit.

Parameters:
  • unit – string representing unit to be used.
  • subset – Pandas slice to convert to percentages
  • precision – int Number of decimal places to round to
  • location – ‘prefix’ or ‘suffix’ indicating where the currency symbol should be.
average(title=u'Average', **kwargs)

Add a mean summary to this table.

Parameters:
  • title – Title to be displayed.
  • kwargs – Keyword arguments passed to numpy.mean.
max(title=u'Maximum', **kwargs)

Add a maximum summary to this table.

Parameters:
  • title – Title to be displayed.
  • kwargs – Keyword arguments passed to numpy.max.
median(title=u'Median', **kwargs)

Add a median summary to this table.

Parameters:
  • title – Title to be displayed.
  • kwargs – Keyword arguments passed to numpy.median.
min(title=u'Minimum', **kwargs)

Add a minimum summary to this table.

Parameters:
  • title – Title to be displayed.
  • kwargs – Keyword arguments passed to numpy.min.
multi_summary(funcs, titles, axis=0, **kwargs)

Add multiple summary rows or columns to the dataframe.

Parameters:
  • funcs – Iterable of functions to be used for a summary.
  • titles – Iterable of titles in the same order as the functions.
  • axis – Same as numpy and pandas axis argument. A value of None will cause the summary to be applied to both rows and columns.
  • kwargs – Keyword arguments passed to all the functions.
classmethod set_locale(locale)

Set the PrettyPandas default locale.

summary(func=<function sum>, title=u'Total', axis=0, **kwargs)

Add multiple summary rows or columns to the dataframe.

Parameters:
  • func – Iterable of functions to be used for a summary.
  • titles – Iterable of titles in the same order as the functions.
  • axis – Same as numpy and pandas axis argument. A value of None will cause the summary to be applied to both rows and columns.
  • kwargs – Keyword arguments passed to all the functions.

The results of summary can be chained together.

total(title=u'Total', **kwargs)

Add a total summary to this table.

Parameters:
  • title – Title to be displayed.
  • kwargs – Keyword arguments passed to numpy.sum.
prettypandas.apply_pretty_globals()

Apply global CSS to make dataframes pretty.

This function injects HTML and CSS code into the notebook in order to make tables look pretty. Third party hosts of notebooks advise against using this and some don’t support it. As long as you are okay with HTML injection in your notebook, go ahead and use this. Otherwise use the PrettyPandas class.