<jupyter_start><jupyter_text>Download, prepare and save the Credit Approval DatasetIn this notebook, you will find guidelines to download, prepare, and store the Credit Approval Dataset 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](http://archive.ics.uci.edu/ml/machine-learning-databases/credit-screening/)- Click on **crx.data** to download the data. - Save crx.data 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/credit+approval).<jupyter_code>import random
import numpy as np
import pandas as pd
# Load data
data = pd.read_csv("crx.data", header=None)

# Create variable names according to UCI Machine Learning
# Repository's information:
varnames = [f"A{s}" for s in range(1, 17)]

# Add column names to dataset:
data.columns = varnames

# Replace ? by np.nan:
data = data.replace("?", np.nan)

# Cast variables to correct datatypes:
data["A2"] = data["A2"].astype("float")
data["A14"] = data["A14"].astype("float")

# Encode target to binary notation:
data["A16"] = data["A16"].map({"+": 1, "-": 0})

# Rename target:
data.rename(columns={"A16": "target"}, inplace=True)

# Display first 5 rows of data:
data.head()
# Add missing values at random positions.

# Set seed for reproducibility:
random.seed(9001)

# Get the reandom position indexes:
values = set([random.randint(0, len(data)) for p in range(0, 100)])

# Add missing data:
data.loc[values, ["A3", "A8", "A9", "A10"]] = np.nan

# Check proportion of missing data:
data.isnull().sum()
# Save dataset

data.to_csv("credit_approval_uci.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13939051918735892, 'fraction_numerical': 0.01805869074492099, 'mean_word_length': 5.332142857142857, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '406480', 'license': 'MIT', 'n_tokens_mistral': 591, 'n_tokens_neox': 564, 'n_words': 185, 'path': 'ch01-missing-data-imputation/donwload-prepare-store-credit-approval-dataset.ipynb', 'repo_name': 'PacktPublishing/Python-Feature-Engineering-Cookbook-Second-Edition', 'size': '1772'}