This file contains hidden or 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
# A shameless copy-paste from the lovely Zufanka, | |
# since I always forget to look here: | |
# https://gist.github.com/zufanka/39b8a55d707b3b4a2a4d369694739561#handling-jsons | |
import json | |
import requests | |
from pandas.io.json import json_normalize | |
r = requests.get("https://api.tenders.exposed/networks/58d77f85-bbc6-447d-a292-c3f17b7936b0/").text | |
data = json.loads(r) |
This file contains hidden or 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
import re | |
import pandas as pd | |
#returns rows that match regexpattern for given column | |
df[df.COLUMNNAME.str.match('REGEXPATTERN', re.IGNORECASE)] |
This file contains hidden or 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
import datetime as dt | |
now = dt.datetime.now().strftime('%y%m%d %H.%M') | |
today = dt.datetime.now().strftime('%y%m%d') |
This file contains hidden or 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
# Thanks Grant Nestor, https://groups.google.com/d/msg/jupyter/Qi9b7z_sgRU/9npQA1zlAgAJ | |
grep --include='*.ipynb' --exclude-dir='.ipynb_checkpoints' -rliw . -e 'search query' |
This file contains hidden or 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
# function that lists files based on filetype | |
def listFiles(dr, ext): | |
return glob(path.join(dr,"*.{}".format(ext))) | |
# example of function: when you want to list all pdfs in working dir | |
pdfs = listFiles('','pdf') | |
# example of function: when you want to list all txts in home dir | |
txts = listFiles('/Users/Name','txt') |
This file contains hidden or 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
# Helpful function to look through the columns of a Pandas dataframe | |
# By Roland Jeannier, https://medium.com/@rtjeannier/pandas-101-fbb5bf86a9bc | |
def eda_helper(df): | |
dict_list = [] | |
for col in df.columns: | |
data = df[col] | |
dict_ = {} | |
# The null count for a column. | |
dict_.update({"null_count" : data.isnull().sum()}) | |
# Counting the unique values in a column |
This file contains hidden or 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
""" | |
The ElementTree documentation shows how to parse XML using XPath: | |
https://docs.python.org/3.4/library/xml.etree.elementtree.html#example | |
""" | |
import xml.etree.ElementTree as ET | |
root = ET.fromstring(countrydata) | |
# Top-level elements |