-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added groubpy function - added network connection check function
- Loading branch information
1 parent
2732f80
commit e1f5f8e
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |