sqltrack.notebook module¶
- sqltrack.notebook.format_dataframe(df: DataFrame, formatting: dict | None = None, na_rep='--', relative_datetimes: bool = True, string_ellipsis: str | bool = 'left') str [source]¶
Returns a copy of the given Pandas DataFrame with formatting applied.
By default the following functions are applied to these the following columns (case-insensitive):
" "
:format_marked()
"m"
:format_marked()
"marked"
:format_marked()
"s"
:format_status()
"status"
:format_status()
"tags"
:format_tags()
"progress"
:format_percentage()
If the column name is not found in the formatting function dictionary, then the formatting function is selected based based on dtype:
Any
datetime
-like:format_datetime_relative()
orformat_datetime()
ifrelative_datetimes
is FalseAny
str
-like:format_string()
with the givenstring_ellipsis
parameter
- Parameters:
formatting – overwrite the default format functions for named columns; names are case-insensitive
relative_datetimes – if True (default), use
format_datetime_relative()
for columns with datetime-like dtype, elseformat_datetime()
string_ellipsis – passed as
ellipsis
parameter toformat_string()
for columns with str-like dtype
- sqltrack.notebook.format_datetime(dt: datetime, sep=' ', timespec='seconds', na_rep='--') str [source]¶
Return datetime in ISO format.
- Parameters:
dt – datetime to format
sep – date and time separator
timespec – precision of the time part, one of ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’
na_rep – replacement string for NaN values
- sqltrack.notebook.format_datetime_relative(dt: datetime, sep=' ', timespec='seconds', na_rep='--') str [source]¶
Return time since given datetime in human-readable form.
- Parameters:
dt – datetime to format
sep – date and time separator
timespec – precision of the time part, one of ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’
na_rep – replacement string for NaN values
- sqltrack.notebook.format_float(v: float, spec='.2f', na_rep='--') str [source]¶
Format a float value.
- Parameters:
v – float value to format
spec – format spec; default
".2f"
na_rep – replacement string for NaN values
- sqltrack.notebook.format_marked(is_marked: bool)[source]¶
If
is_marked
is True, return a gold star, else empty string.
- sqltrack.notebook.format_percentage(v, mul=100, spec='.1f', na_rep='--') str [source]¶
Returns a percentage value with bar in background.
- Parameters:
v – percentage value to format
mul – multiplicative factor for display; defaults to 100 for float values in [0,1]
spec – format spec; default
".1f"
na_rep – replacement string for NaN values