<jupyter_start><jupyter_text>Notebook by <NAME>Released under MIT LicenseGitHub: [github.com/RuchirChawdhry/Jupyter-Notebooks](https://github.com/RuchirChawdhry/Jupyter-Notebooks)LinkedIn: [linkedin.com/in/RuchirChawdhry](https://linkedin.com/in/RuchirChawdhry)Website: [ruchirchawdhry.com](https://ruchirchawdhry.com)---  Boltons Module<jupyter_code>import requests
from collections import Counter
from itertools import chain
from boltons.urlutils import URL
from boltons.urlutils import find_all_links
from boltons.strutils import camel2under
from boltons.strutils import under2camel
from boltons.strutils import slugify
from boltons.strutils import split_punct_ws
from boltons.strutils import ordinalize
from boltons.strutils import cardinalize
from boltons.strutils import pluralize
from boltons.strutils import singularize
from boltons.strutils import is_uuid
from boltons.strutils import html2text
from boltons.strutils import bytes2human
from boltons.strutils import find_hashtags
from boltons.strutils import gzip_bytes
from boltons.strutils import gunzip_bytes
from boltons.statsutils import Stats
from boltons.statsutils import describe<jupyter_output><empty_output><jupyter_text>jsonutils: JSON  urlsutils: URL<jupyter_code># https://boltons.readthedocs.io/en/latest/urlutils.html
url = URL('https://www.amazon.in/s?k=smartphones&ref=nb_sb_noss_2')
print(url.host)
print(url.qp['k'])
print(url.scheme)
print(url.path)
url = URL('https://www.croma.com/apple-iphone-11-pro-max-midnight-green-256-gb-4-gb-ram-/p/221136')
print(url.host)
print(url.scheme)
print(url.path)
print(url.path_parts)
url = URL('https://www.naukri.com/job-listings-Big-Data-Engineer-Newstar-corporation-Bengaluru-4-to-7-years-280619500530?src=seo_srp&sid=15725119141420&xp=1&px=1')
print(url.host)
print(url.scheme)
print(url.path)
print(url.qp['sid'])
print(url.qp['src'])
print(url.qp['xp'])
print(url.qp['px'])
print(url.to_text())
print(url.path_parts)
print(url.qp.values())
sitemap = '''<url>
<loc>
https://www.naukri.com/office-of-the-district-education-officer-muzaffarpur-jobs-careers-4196292
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>
<url>
<loc>
https://www.naukri.com/ambedkar-university-delhi-jobs-careers-763676
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>
<url>
<loc>
https://www.naukri.com/indian-institute-of-technology-hyderabad-jobs-careers-768880
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>'''

links = find_all_links(sitemap)
links_with_text = find_all_links(sitemap, with_text=True)

urls_path = [link.path for link in links]
print('Links: \n\n', links)
print(urls_path)<jupyter_output>['/office-of-the-district-education-officer-muzaffarpur-jobs-careers-4196292', '/ambedkar-university-delhi-jobs-careers-763676', '/indian-institute-of-technology-hyderabad-jobs-careers-768880']<jupyter_text>strutils: Text<jupyter_code>camel_to_under = camel2under('CamelCase')
print(camel_to_under)
under_to_camel = under2camel('not_camel_case')
print(under_to_camel)
slug = slugify('This is a blog post')
print(slug)
slug = slugify("this is my first post", delim='-')
print(slug)
to_split = split_punct_ws(
    'job-listings-Big-Data-Engineer-Newstar-corporation-Bengaluru-4-to-7-years-280619500530'
)
print(to_split)

# split_punct_ws can be useful in webscraping to extract data easily from the URL
# sometimes, this allows you to avoid hitting the page as the URL itself can contain the info desired
# note: this splits on punctuation and whitespace
ordinalize(1)
num_list = [1, 2, 22, 100, 3, 44, 72, 1000]
ordinalized = [ordinalize(num) for num in num_list]
print(ordinalized)
v = 'aeiou'
cardinalize('vowel', len(v))
v = 'a'
cardinalize('vowel', len(v))
f = ('Amanita argentea', 'Calyptella campanula', 'Entoloma chalybaeum')
cardinalize('fungus', Counter(v))
print(pluralize('mouse'))
print(pluralize('student'))
print(pluralize('Number'))

# returns the plural of a word and preserves the case
print(singularize('mice'))
print(singularize('fungi'))
print(singularize('Floors'))

# returns the singular of a word and preserves the case
to_check_1 = 'e682ccca-5a4c-4ef2-9711-73f9ad1e15ea'
to_check_2 = '0221f0d9-d4b9-11e5-a478-10ddb1c2feb9'
print(is_uuid(to_check_1))
print(is_uuid(to_check_2))
print(is_uuid(to_check_2, version=1))
sitemap = '''<url>
<loc>
https://www.naukri.com/office-of-the-district-education-officer-muzaffarpur-jobs-careers-4196292
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>
<url>
<loc>
https://www.naukri.com/ambedkar-university-delhi-jobs-careers-763676
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>
<url>
<loc>
https://www.naukri.com/indian-institute-of-technology-hyderabad-jobs-careers-768880
</loc>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
<lastmod>2019-10-15T04:00:03+05:30</lastmod>
</url>'''

print(html2text(sitemap))

# the above is not html but this obviously works on xml as well
bytes_1 = 10000001221
bytes_2 = 101221

print(bytes2human(bytes_1, 2))
print(bytes2human(bytes_2, 2))
sample_text = 'A hashtag looks something like this:  #python or #github.'

print(find_hashtags(sample_text))
response = requests.get('https://en.wikipedia.org/wiki/The_Wreck_of_the_Titan:_Or,_Futility').content
r_gzipped = gzip_bytes(bytes(response), level=9) # level 9 is highest, 1 is lowest

print(len(response))
print(len(r_gzipped))<jupyter_output>75787
19275<jupyter_text>statsutils - Statistics Basics<jupyter_code>num_list = [22, 1, 983, 1, 0, 24, 6, 7, 9, 4, 7, 777]
stats = Stats(num_list)

print(stats.mean)
print(stats.min)
print(stats.max)
print(stats.variance)
print(stats.median)
print(stats.count)
print(stats.std_dev)
print(stats.describe())
print(stats.format_histogram())
print(stats.median_abs_dev) # median absolute deviation
print(stats.trimean)
print(stats.kurtosis)
print(stats.skewness)
print(stats.mad)
print(stats.iqr) # interquartile range
print(stats.get_quantile(0.8))
print(stats.get_zscore(55))
print(stats.rel_std_dev) # relative standard deviate
print(stats.pearson_type)
stats.get_histogram_counts()
describe(num_list)<jupyter_output><empty_output><jupyter_text>tableutils<jupyter_code># https://boltons.readthedocs.io/en/latest/tableutils.html<jupyter_output><empty_output><jupyter_text>fileutils<jupyter_code># https://boltons.readthedocs.io/en/latest/fileutils.html<jupyter_output><empty_output><jupyter_text>ecoutils<jupyter_code># https://boltons.readthedocs.io/en/latest/ecoutils.html<jupyter_output><empty_output><jupyter_text>ioutils<jupyter_code># https://boltons.readthedocs.io/en/latest/_modules/boltons/ioutils.html#MultiFileReader<jupyter_output><empty_output><jupyter_text>setutils<jupyter_code># https://boltons.readthedocs.io/en/latest/setutils.html<jupyter_output><empty_output><jupyter_text>iterutils<jupyter_code># https://boltons.readthedocs.io/en/latest/iterutils.html<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14555633310007, 'fraction_numerical': 0.05038488453463961, 'mean_word_length': 7.568345323741007, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 100, 'https://': 20, 'lorem ipsum': 0, 'www.': 9, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '248830', 'license': 'MIT', 'n_tokens_mistral': 3054, 'n_tokens_neox': 2808, 'n_words': 417, 'path': 'module_boltons.ipynb', 'repo_name': 'RuchirChawdhry/Jupyter-Notebooks', 'size': '7154'}