<jupyter_start><jupyter_text>Download, prepare and save the Bag of Words Data SetIn this notebook, you will find guidelines to download, prepare, and store the Bag of Words Data Set from the [UCI Machine Learning Repository](http://archive.ics.uci.edu/ml). Download the dataFollow these guidelines to download the data:- Visit [the UCI website](https://archive.ics.uci.edu/ml/machine-learning-databases/bag-of-words/)- Click on **docword.enron.txt.gz** to download the data.- Unzip the data and save it in the same folder that contains this notebook.- Then click on **vocab.enron.txt** to download the word names.- Save vocab.enron.txt in the same folder that contains this notebook.You can find more information about this particular dataset [here](https://archive.ics.uci.edu/ml/datasets/Bag+of+Words).<jupyter_code>import pandas as pd
# load the word counts

data = pd.read_csv("docword.enron.txt", sep=" ", skiprows=3, header=None)
data.columns = ["docID", "wordID", "count"]

data.head()
# load the words

words = pd.read_csv("vocab.enron.txt", header=None)
words.columns = ["words"]

words.head()
# select at random 10 words

words = words.sample(10, random_state=290917)

words
data = words.merge(data, left_index=True, right_on="wordID")

data.head()
# reconstitute the bag of words dataset

bow = data.pivot(index="docID", columns="words", values="count")
bow.fillna(0, inplace=True)
bow.reset_index(inplace=True, drop=True)
bow.shape
bow.head()
bow.to_csv("bag_of_words.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12827225130890052, 'fraction_numerical': 0.007853403141361256, 'mean_word_length': 5.42436974789916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '615898', 'license': 'MIT', 'n_tokens_mistral': 499, 'n_tokens_neox': 481, 'n_words': 153, 'path': 'ch04-discretization/donwload-prepare-store-enron-data.ipynb', 'repo_name': 'PacktPublishing/Python-Feature-Engineering-Cookbook-Second-Edition', 'size': '1528'}