Skip to content

Commit

Permalink
Minor Feature Upgrade v.1.9.6
Browse files Browse the repository at this point in the history
- added groubpy function
- added network connection check function
  • Loading branch information
mikkokotila committed Jan 1, 2019
1 parent 2732f80 commit e1f5f8e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
52 changes: 52 additions & 0 deletions wrangle/groupby_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np

def groupby_func(data, func):

'''Streamlines the process of creating various
groupby elements in Pandas. Takes in a dataframe
and one of the supported functions as a string:
'median'
'mean'
'first'
'last'
'std'
'mode'
'max'
'min'
'sum'
'random'
'freq'
All are standard Pandas functions, except 'random'
and 'freq' are custom.
'''


if func == 'median':
out = data.median()
elif func == 'mean':
out = data.mean()
elif func == 'first':
out = data.first()
elif func == 'last':
out = data.last()
elif func == 'std':
out = data.std()
elif func == 'mode':
out = data.mode()
elif func == 'max':
out = data.max()
elif func == 'min':
out = data.min()
elif func == 'sum':
out = data.sum()
elif func == 'random':
out = data.agg(np.random.choice)
elif func == 'freq':
out = data.agg(lambda x: x.value_counts().index[0])

out = out.reset_index()

return out
10 changes: 10 additions & 0 deletions wrangle/network_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import socket


def network_check():
try:
socket.create_connection(("www.google.com", 80))
return True
except OSError:
pass
return False

0 comments on commit e1f5f8e

Please sign in to comment.