isaricanalytics.utils

isaricanalytics.utils.clean_figure_table(figure_table: DataFrame) DataFrame[source]

pandas.DataFrame : A cleaned figure table dataframe.

This function is not intended to be highly generic, but was written with the aim of producing clean dataframes for the plotting functions in the isaricanalytics.visualisation library. The cleaning steps are:

  • removal of HTML styling elements

  • removal of non-standard (non-alphabetic) Unicode characters, currently limited to .

Parameters:
figure_tablepandas.DataFrame

The original figure table as a Pandas dataframe.

Returns:
pandas.DataFrame

The cleaned figure table.

Examples

>>> import io, pandas as pd
>>> pd.set_option("display.max_columns", None)
>>> data = pd.read_csv(io.StringIO(
...     '''
...     A,B,C
...     <b>A1</b>,<i>A2</i>,<b><i>A3</i></b>
...     <b>B1</b>,<i>B2</i>,<b><i>B3</i></b>
...     <b>C1</b>,<i>C2</i>,<b><i>C3</i></b>
...     '''
... ), skipinitialspace=True)
>>> cleaned_data = clean_figure_table(data)
>>> cleaned_data
    A   B   C
0  A1  A2  A3
1  B1  B2  B3
2  C1  C2  C3
isaricanalytics.utils.strip_html(value: Any) str | Any[source]

typing.Any : Strip HTML elements from a value.

Parameters:
valuetyping.Any

A value.

Returns:
str, typing.Any

Either a string stripped of all HTML elements, or the original non- string value.

Examples

>>> strip_html("<b><i>A value</i></b>")
'A value'
>>> strip_html("<p>This is a paragraph.</p>")
'This is a paragraph.'
isaricanalytics.utils.strip_nonstandard_unicode_chars(value: Any) str | Any[source]

typing.Any : Strip non-standard Unicode characters from a value.

The non-standard Unicode characters of interest are defined within the function itself, and are currently limited to the “↳” (U+21B3) character, but may be extended to include other characters.

Parameters:
valuetyping.Any

A value.

Returns:
str, typing.Any

Either a string stripped of all non-standard Unicode characters, or the original non- string value.

Examples

>>> strip_nonstandard_unicode_chars("A value with a special Unicode ↳ character")
'A value with a special Unicode  character'
>>> strip_nonstandard_unicode_chars("<p>This is a paragraph ending with a special Unicode character ↳.</p>")
'<p>This is a paragraph ending with a special Unicode character .</p>'