{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "import random\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "num_records = 100\n", "first_names = [\"Alan\", \"Miguel\", \"Lakshmi\", \"Chen\", \"Oluwaseun\", \"Dmitri\", \"Nadia\", \"John\", \"Jane\", \"Alice\", \"Terrance\", \"Elena\"]\n", "last_names = [\"Patel\", \"Rodriguez\", \"Kim\", \"Okafor\", \"Nasser\", \"Ivanov\", \"Smith\", \"Brown\", \"Johnson\", \"Lee\", \"Malcolm\", \"Chatterjee\"]\n", "# new last names\n", "judge_last_names = [\"James\", \"Skaarsgard\", \"Oleg\", \"Morgan\", \"Brown\", \"Connor\"]\n", "case_types = [\"Criminal\", \"Civil\", \"Family\", \"Criminal\", \"Civil\", \"Family\"]\n", "cities = ['new York', 'LOS angeles', 'chicago', 'houston', 'BOSTON']\n", "weather_types = ['sunny', 'cloudy', 'rainy', 'snowy']\n", "get_random_date = lambda: f'2023-0{random.randint(1,9)}-{random.randint(10,28)}'\n", "get_random_case_number = lambda: f'{random.choice([\"CR\", \"CASE\"])}-{random.randint(1000,9999)}'\n", "get_random_fee = lambda: random.choice([100, 150, 200, 250])\n", "\n", "get_random_int = lambda: random.randint(1000, 9999)\n", "\n", "# Define column names with standard casing\n", "case_date_col = 'case_date'\n", "lastname_col = 'lastname'\n", "firstname_col = 'firstname'\n", "case_type_col = 'case_type'\n", "case_id_col = 'case_id'\n", "court_fee_col = 'court_fee'\n", "jurisdiction_col = 'jurisdiction'\n", "case_id_prefix = 'CR'\n", "\n", "# Use inconsistent casing for values\n", "legal_entries_a_data = {\n", " case_date_col: [get_random_date() for _ in range(num_records)],\n", " lastname_col: [random.choice(last_names) for _ in range(num_records)],\n", " firstname_col: [random.choice(first_names) for _ in range(num_records)],\n", " case_type_col: [random.choice(case_types) for _ in range(num_records)],\n", " case_id_col: [f'{case_id_prefix}-{get_random_int()}' for _ in range(num_records)],\n", " court_fee_col: [get_random_fee() for _ in range(num_records)],\n", " jurisdiction_col: [random.choice(cities) for _ in range(num_records)],\n", " 'judge_last_name': [random.choice(judge_last_names) for _ in range(num_records)]\n", "}\n", "\n", "legal_entries_a = pd.DataFrame(legal_entries_a_data)\n", "\n", "# Apply the transform_row function for legal_entries_A to create legal_entries_B\n", "def transform_row(row):\n", " return pd.Series({\n", " 'Date_of_Case' : row[case_date_col].replace(\"-\", \"/\"),\n", " 'Fee' : float(row[court_fee_col]),\n", " 'FullName' : f\"{row[firstname_col]} {row[lastname_col]}\".title(),\n", " 'CaseNumber' : f'{row[case_id_col].replace(case_id_prefix, \"case-\")}',\n", " 'CaseKind' : row[case_type_col].capitalize(),\n", " 'Date_of_Case' : row[case_date_col].replace(\"-\", \"/\"),\n", " 'Location' : row[jurisdiction_col].replace(\" \", \"\")[:random.randint(4,5)].upper(),\n", " 'Weather': random.choice(weather_types)\n", " })\n", "\n", "def transform_to_template(row):\n", " return pd.Series({\n", " 'CaseDate': row[case_date_col],\n", " 'FullName': f\"{row[firstname_col]} {row[lastname_col]}\",\n", " 'CaseType': \"Family\" if \"Fam\" in row[case_type_col] else \"Civil\" if 'Civ' in row[case_type_col] else row[case_type_col].capitalize(),\n", " 'CaseID': f'{row[case_id_col].replace(case_id_prefix, \"CASE\")}',\n", " 'Fee': row[court_fee_col],\n", " 'Jurisdiction': row[jurisdiction_col].title()\n", " })\n", "\n", "legal_entries_b = legal_entries_a.apply(transform_row, axis=1)\n", "legal_template = legal_entries_a.apply(transform_to_template, axis=1)\n", "\n", "data_dir_path = os.path.join(os.getcwd(), \"data\")\n", "legal_entries_a.to_csv(os.path.join(data_dir_path, \"legal_entries_a.csv\"), index=False)\n", "legal_entries_b.to_csv(os.path.join(data_dir_path, \"legal_entries_b.csv\"), index=False)\n", "legal_template.to_csv(os.path.join(data_dir_path, \"legal_template.csv\"), index=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }