<jupyter_start><jupyter_text>Delete Data<jupyter_code>%load_ext lab_black
%load_ext autoreload
%autoreload 2
import configparser
import os
import shutil
from glob import glob

from sqlalchemy import create_engine
# Database
table_name = "ridership"
path_to_sql_cfg = "../sql.ini"
if not os.path.isfile(path_to_sql_cfg):
    DB_TYPE = os.getenv("DB_TYPE")
    DB_DRIVER = os.getenv("DB_DRIVER")
    DB_USER = os.getenv("DB_USER")
    DB_PASS = os.getenv("DB_PASS")
    DB_HOST = os.getenv("DB_HOST")
    DB_PORT = os.getenv("DB_PORT")
else:
    config = configparser.ConfigParser()
    config.read("../sql.ini")
    default_cfg = config["default"]
    DB_TYPE = default_cfg["DB_TYPE"]
    DB_DRIVER = default_cfg["DB_DRIVER"]
    DB_USER = default_cfg["DB_USER"]
    DB_PASS = default_cfg["DB_PASS"]
    DB_HOST = default_cfg["DB_HOST"]
    DB_PORT = default_cfg["DB_PORT"]
DB_NAME = "bikeshare"
# Connect to single database (required to create database)
URI_NO_DB = f"{DB_TYPE}+{DB_DRIVER}://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}"

# Connect to all databases (required to perform CRUD operations and submit queries)
URI = f"{DB_TYPE}+{DB_DRIVER}://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"<jupyter_output><empty_output><jupyter_text>Drop Database with Processed Data Drop the `ridership` table in the `bikeshare` database<jupyter_code>engine = create_engine(URI)
conn = engine.connect()
_ = conn.execute(f"DROP TABLE IF EXISTS {table_name}")
conn.close()
engine.dispose()<jupyter_output><empty_output><jupyter_text>Drop the `bikeshare` database<jupyter_code>engine = create_engine(URI_NO_DB)
conn = engine.connect()
_ = conn.execute(f"DROP DATABASE IF EXISTS {DB_NAME};")
conn.close()
engine.dispose()<jupyter_output><empty_output><jupyter_text>Delete Files and Folders  Delete Saved Charts<jupyter_code>saved_image_files = glob(f"reports/figures/*.png")
for f in saved_image_files:
    os.remove(f)<jupyter_output><empty_output><jupyter_text>Delete Intermediate Processed Data<jupyter_code>processed_data_files = [
    f
    for files_list in [glob(f"data/processed/*.{ext}") for ext in ["xlsx", "csv"]]
    for f in files_list
]
for f in processed_data_files:
    os.remove(f)<jupyter_output><empty_output><jupyter_text>Delete Raw Supplementary Datasets<jupyter_code>raw_data_dirs = glob("data/raw/*")
for pdir in raw_data_dirs:
    shutil.rmtree(pdir)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12943632567849686, 'fraction_numerical': 0.0004175365344467641, 'mean_word_length': 6.327217125382263, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '630286', 'license': 'MIT', 'n_tokens_mistral': 906, 'n_tokens_neox': 892, 'n_words': 163, 'path': 'v1/notebooks/old-versions/2_delete_data.ipynb', 'repo_name': 'elsdes3/bikeshare-dash', 'size': '2395'}