AMKhakbaz commited on
Commit
255e202
·
verified ·
1 Parent(s): 0087f84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -5,6 +5,12 @@ import plotly.express as px
5
  import plotly.graph_objects as go
6
  from scipy.stats import norm
7
 
 
 
 
 
 
 
8
  def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3', width=800, height=600):
9
  if plot_type == "Scatter":
10
  fig = go.Figure()
@@ -96,7 +102,6 @@ def is_matching_pattern(column, prefix):
96
  return True
97
  return False
98
 
99
-
100
  def multi_answer(df):
101
  friquency = {}
102
  for i in df.columns:
@@ -112,7 +117,6 @@ def multi_answer(df):
112
  friquency_dataframe.loc[len(friquency_dataframe)] = ['Sample_size', len(df.dropna(how='all')), 1]
113
  return friquency_dataframe
114
 
115
-
116
  def single_answer(df):
117
  counter = df.value_counts()
118
  friquency_dataframe = pd.DataFrame({
@@ -137,6 +141,8 @@ def two_variable_ss(df, var1, var2):
137
  counter = df.groupby(var1)[var2].value_counts()
138
  friquency_dataframe = counter.unstack(fill_value=0)
139
 
 
 
140
  column_sums = friquency_dataframe.sum(axis=0)
141
  percentage_dataframe = friquency_dataframe.div(column_sums, axis=1) * 100
142
 
@@ -161,6 +167,9 @@ def two_variable_sm(df, var1, var2):
161
 
162
  friquency_dataframe.index, percentage_dataframe.index = value, value
163
 
 
 
 
164
  friquency_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,1])[:-1]
165
  friquency_dataframe.loc['Sample_size'] = list(single_answer(df[var1]).iloc[:,1])
166
  percentage_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,2])[:-1]
@@ -183,6 +192,9 @@ def two_variable_mm(df, var1, var2):
183
 
184
  friquency_dataframe.index, percentage_dataframe.index = value, value
185
 
 
 
 
186
  friquency_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,1])[:-1]
187
  friquency_dataframe.loc['Sample_size'] = list(multi_answer(df[var1]).iloc[:,1])
188
  percentage_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,2])[:-1]
 
5
  import plotly.graph_objects as go
6
  from scipy.stats import norm
7
 
8
+ def sorting(df):
9
+ df.index = list(map(float, df.index))
10
+ df = df.sort_index
11
+
12
+ return df
13
+
14
  def figo(plot_type, df, title, xlabel=None, ylabel=None, legend_title=None, colorscale='Plotly3', width=800, height=600):
15
  if plot_type == "Scatter":
16
  fig = go.Figure()
 
102
  return True
103
  return False
104
 
 
105
  def multi_answer(df):
106
  friquency = {}
107
  for i in df.columns:
 
117
  friquency_dataframe.loc[len(friquency_dataframe)] = ['Sample_size', len(df.dropna(how='all')), 1]
118
  return friquency_dataframe
119
 
 
120
  def single_answer(df):
121
  counter = df.value_counts()
122
  friquency_dataframe = pd.DataFrame({
 
141
  counter = df.groupby(var1)[var2].value_counts()
142
  friquency_dataframe = counter.unstack(fill_value=0)
143
 
144
+ friquency_dataframe = sorting(friquency_dataframe)
145
+
146
  column_sums = friquency_dataframe.sum(axis=0)
147
  percentage_dataframe = friquency_dataframe.div(column_sums, axis=1) * 100
148
 
 
167
 
168
  friquency_dataframe.index, percentage_dataframe.index = value, value
169
 
170
+ friquency_dataframe = sorting(friquency_dataframe)
171
+ percentage_dataframe = sorting(percentage_dataframe)
172
+
173
  friquency_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,1])[:-1]
174
  friquency_dataframe.loc['Sample_size'] = list(single_answer(df[var1]).iloc[:,1])
175
  percentage_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,2])[:-1]
 
192
 
193
  friquency_dataframe.index, percentage_dataframe.index = value, value
194
 
195
+ friquency_dataframe = sorting(friquency_dataframe)
196
+ percentage_dataframe = sorting(percentage_dataframe)
197
+
198
  friquency_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,1])[:-1]
199
  friquency_dataframe.loc['Sample_size'] = list(multi_answer(df[var1]).iloc[:,1])
200
  percentage_dataframe['Total'] = list(multi_answer(df[var2]).iloc[:,2])[:-1]