Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturstrag committed Aug 14, 2023
1 parent b2e1c84 commit 17448c1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ord_info_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
"""ord_info_function.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1wXpxeji9dvkf_LuXuxA54BElELaBYg6m
"""

import pandas as pd
import numpy as np

indicators = {'not satisfied', 'ok', 'excellent'}

ds = ['not satisfied', 'not satisfied', 'not satisfied', 'ok', 'ok', 'ok','ok','ok','ok','ok','ok','ok','ok', 'excellent',
'excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent',
'excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent',
'excellent','excellent','excellent','excellent','excellent','excellent','excellent','excellent']

def ord_info(ds, indicators):

# Calculate frequency using pandas value_counts()
freq_counts = pd.value_counts(ds, ascending=True)
freq_counts_df = pd.DataFrame(freq_counts, columns = ['frequency'])

# Calculate percent
total_responses = len(ds)
freq_counts_df["percent"] = (freq_counts_df["frequency"] / total_responses) * 100

# Create DataFrame with all possible indicators
indicators_df = pd.DataFrame(indicators, columns=["indicator"])
indicators_df.set_index("indicator", inplace=True)

# Merge the frequency and percent DataFrames to include 0 counts for missing indicators
summary_df = indicators_df.merge(freq_counts_df, how="left", left_index=True, right_index=True)
summary_df.fillna(0, inplace=True)

# Calculate cumulative percent
summary_df["cumulative"] = summary_df["percent"].cumsum()

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

# Create the final DataFrame
summary_df.index.name = "indicators"
return summary_df

ord_info(ds,indicators)

0 comments on commit 17448c1

Please sign in to comment.