-
Notifications
You must be signed in to change notification settings - Fork 34
/
com_util.py
49 lines (41 loc) · 1.65 KB
/
com_util.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
47
48
49
import pandas as pd
def merge_count(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].count()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_nunique(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].nunique()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_median(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].median()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_mean(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].mean()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_sum(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].sum()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_max(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].max()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_min(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].min()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df
def merge_std(df,columns,value,cname):
add = pd.DataFrame(df.groupby(columns)[value].std()).reset_index()
add.columns=columns+[cname]
df=df.merge(add,on=columns,how="left")
return df