-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_describe.py
46 lines (38 loc) · 1.65 KB
/
func_describe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import plotly.graph_objects as go
import pandas as pd
def descriptives(df):
df = df.dropna(subset=['pre_total', 'post_total'], how='any')
des_dict = dict()
des_dict['pre_des'] = df['pre_total'].describe()
des_dict['post_des'] = df['post_total'].describe()
des_dict['diff_des'] = df['diff'].describe()
return des_dict
def descriptives_group(df, group):
df = df.dropna(subset=[group, 'pre_total', 'post_total'], how='any')
check = pd.notna(df[group]).sum()
if check > 0:
des_dict = dict()
des_dict['pre_des'] = df.groupby(group)['pre_total'].describe(include='all')
des_dict['post_des'] = df.groupby(group)['post_total'].describe(include='all')
des_dict['diff_des'] = df.groupby(group)['diff'].describe(include='all')
return des_dict
else:
return 'na_cat'
def dom_descriptives(df):
df = df.dropna(subset=['pre_mm_score', 'post_mm_score'], how='any')
des_dict = dict()
des_dict['pre_des'] = df['pre_mm_score'].describe()
des_dict['post_des'] = df['post_mm_score'].describe()
des_dict['diff_des'] = df['diff_mm_score'].describe()
return des_dict
def dom_descriptives_group(df, group):
df = df.dropna(subset=[group, 'pre_mm_score', 'post_mm_score'], how='any')
check = pd.notna(df[group]).sum()
if check > 0:
des_dict = dict()
des_dict['pre_des'] = df.groupby(group)['pre_mm_score'].describe(include='all')
des_dict['post_des'] = df.groupby(group)['post_mm_score'].describe(include='all')
des_dict['diff_des'] = df.groupby(group)['diff_mm_score'].describe(include='all')
return des_dict
else:
return 'na_cat'