Skip to content

Commit

Permalink
feat: render constant as italic (#114)
Browse files Browse the repository at this point in the history
Render constant in constant occurrence as italic instead of in quotes,
which makes the value look like a string.

Resolves #57
  • Loading branch information
mbelak-dtml authored Sep 4, 2023
1 parent cc950c6 commit 9fa36a4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions edvart/report_sections/dataset_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,29 +778,33 @@ def constant_occurrence(
constant_count = (df == constant).sum()
constant_percentage = 100 * constant_count / len(df)

constant_formatted = f"<i>{constant!r}</i>"
constant_count_name = f"{constant_formatted} Count"
constant_perc_name = f"{constant_formatted} %"

# Convert series to frames
constant_count_frame = series_to_frame(
series=constant_count,
index_name="Column Name",
column_name=f'"{constant}" Count',
column_name=constant_count_name,
)

constant_percentage_frame = series_to_frame(
series=constant_percentage,
index_name="Column Name",
column_name=f'"{constant}" %',
column_name=constant_perc_name,
)

# Merge absolute and relative counts
constant_stats_frame = constant_count_frame.merge(
constant_percentage_frame, on="Column Name"
).sort_values(f'"{constant}" %', ascending=False)
).sort_values(constant_perc_name, ascending=False)

# Display table
display(
hide_index(constant_stats_frame)
.bar(color="#FFA07A", subset=[f'"{constant}" %'], vmax=100)
.format({f'"{constant}" %': "{:.03f}"})
.bar(color="#FFA07A", subset=[constant_perc_name], vmax=100)
.format({constant_perc_name: "{:.03f}"})
)

def required_imports(self) -> List[str]:
Expand Down

0 comments on commit 9fa36a4

Please sign in to comment.