Formats (datascience.formats)

String formatting for table entries.

class datascience.formats.CurrencyFormatter(symbol='$', *args, **vargs)[source]

Format currency and convert to float.

convert_value(value)[source]

Convert value to float. If value is a string, ensure that the first character is the same as symbol ie. the value is in the currency this formatter is representing.

format_value(value)[source]

Format currency.

class datascience.formats.DateFormatter(format='%Y-%m-%d %H:%M:%S.%f', *args, **vargs)[source]

Format date & time and convert to UNIX timestamp.

convert_value(value)[source]

Convert 2015-08-03 to a Unix timestamp int.

format_value(value)[source]

Format timestamp as a string.

class datascience.formats.DistributionFormatter(decimals=2, *args, **vargs)[source]

Normalize a column and format as percentages.

convert_column(values)[source]

Normalize values.

class datascience.formats.Formatter(min_width=None, max_width=None, etc=None)[source]

String formatter that truncates long values.

convert_column(values)[source]

Convert each value using the convert_value method.

static convert_value(value)[source]

Identity conversion (override to convert values).

property converts_values

Whether this Formatter also converts values.

etc = ' ...'
format_column(label, column)[source]

Return a formatting function that pads & truncates values.

static format_value(value)[source]

Pretty-print an arbitrary value.

max_width = 60
min_width = 4
class datascience.formats.NumberFormatter(decimals=2, decimal_point='.', separator=',', int_to_float=False, *args, **vargs)[source]

Format numbers that may have delimiters.

convert_value(value)[source]

Convert string 93,000.00 to float 93000.0.

format_value(value)[source]

Pretty-print an arbitrary value.

class datascience.formats.PercentFormatter(decimals=2, *args, **vargs)[source]

Format a number as a percentage.

format_value(value)[source]

Format number as percentage.