Skip to content

Commit

Permalink
implementing issue 39
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckony committed Mar 25, 2024
1 parent 8baca79 commit 423d6bf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def info(ds: Sequence, indicators: ArrayLike) -> pd.DataFrame:
# Calculate ratio
total_responses = len(ds)
counts_to_total = freq_counts_df["frequency"] / total_responses
freq_counts_df["ratio"] = counts_to_total * 100
freq_counts_df["ratio %"] = counts_to_total * 100

# Add all indicators
summary_df = pd.DataFrame(index=indicators, columns=["frequency", "ratio"])
summary_df = pd.DataFrame(index=indicators, columns=["frequency", "ratio %"])
summary_df.index.name = "indicator"

# Merge the frequency and percent DataFrames
Expand All @@ -43,10 +43,10 @@ def info(ds: Sequence, indicators: ArrayLike) -> pd.DataFrame:
summary_df.fillna(0, inplace=True)

# Calculate cumulative percent
summary_df["cumulative"] = summary_df["ratio"].cumsum()
summary_df["cumulative"] = summary_df["ratio %"].cumsum()/100

# Set the last cumulative value to 100
summary_df.loc[summary_df["cumulative"] > 100, "cumulative"] = 100
summary_df.loc[summary_df["cumulative"] > 1, "cumulative"] = 1

# Create the final DataFrame
return summary_df
Expand Down

0 comments on commit 423d6bf

Please sign in to comment.