Skip to content

Commit

Permalink
handle v high or v low code proportions
Browse files Browse the repository at this point in the history
  • Loading branch information
LFISHER7 committed Aug 10, 2023
1 parent 546252d commit fc5da04
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion interactive_templates/templates/v2/analysis/top_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def create_top_5_code_table(

event_counts.rename(columns={code_column: "Code"}, inplace=True)

# because of rounding, some codes can appear as either 0.00% or 100.00%. If they are
# not truly 0.00% or 100.00%, we want to display them as <0.001% or >99.99% respectively
event_counts.loc[
(event_counts["Proportion of codes (%)"] == 0) & (event_counts["num"] > 0),
"Proportion of codes (%)",
] = "<0.001"

event_counts.loc[
(event_counts["Proportion of codes (%)"] == 100)
& (event_counts["num"] < total_events),
"Proportion of codes (%)",
] = ">99.99"

# sort by proportion of codes
event_counts = event_counts.sort_values(
ascending=False, by="Proportion of codes (%)"
Expand All @@ -120,7 +133,7 @@ def create_top_5_code_table(
:, ["Code", "Description", "Proportion of codes (%)"]
]
# return top n rows
return event_counts.head(5), event_counts_with_counts
return event_counts.head(nrows), event_counts_with_counts


def parse_args():
Expand Down

0 comments on commit fc5da04

Please sign in to comment.