Diff of /generating_data.ipynb [000000] .. [ba27f9]

Switch to unified view

a b/generating_data.ipynb
1
{
2
 "cells": [
3
  {
4
   "cell_type": "code",
5
   "execution_count": null,
6
   "id": "04c762a0-d289-4e23-b0f3-3ea6b3aa2e32",
7
   "metadata": {},
8
   "outputs": [],
9
   "source": [
10
    "import pandas as pd\n",
11
    "import numpy as np\n",
12
    "\n",
13
    "# Patients table\n",
14
    "np.random.seed(0)\n",
15
    "num_rows = 10000\n",
16
    "patients = pd.DataFrame({\n",
17
    "    'patient_id': np.arange(1, num_rows + 1),\n",
18
    "    'age': np.random.randint(18, 85, num_rows),\n",
19
    "    'gender': np.random.choice(['Male', 'Female'], num_rows),\n",
20
    "    'admission_date': pd.date_range('2020-01-01', periods=num_rows),\n",
21
    "    'discharge_date': pd.date_range('2020-01-15', periods=num_rows)\n",
22
    "})\n",
23
    "\n",
24
    "# Diagnoses table\n",
25
    "diagnoses = pd.DataFrame({\n",
26
    "    'diagnosis_id': np.arange(1, num_rows + 1),\n",
27
    "    'patient_id': patients['patient_id'],\n",
28
    "    'icd_code': np.random.choice(['A00-B99', 'C00-D49', 'D50-D89', 'E00-E89', 'F00-F99'], num_rows),\n",
29
    "    'diagnosis_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
30
    "})\n",
31
    "\n",
32
    "# Medications table\n",
33
    "medications = pd.DataFrame({\n",
34
    "    'medication_id': np.arange(1, num_rows + 1),\n",
35
    "    'patient_id': patients['patient_id'],\n",
36
    "    'medication_name': np.random.choice(['Medication A', 'Medication B', 'Medication C', 'Medication D', 'Medication E'], num_rows),\n",
37
    "    'start_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
38
    "})\n",
39
    "\n",
40
    "medications = medications.merge(patients[['patient_id', 'admission_date', 'discharge_date']], on='patient_id')\n",
41
    "\n",
42
    "medications['end_date'] = [pd.date_range(row['start_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['start_date'], row['discharge_date']))) - 1] if len(pd.date_range(row['start_date'], row['discharge_date'])) > 1 else row['discharge_date'] for index, row in medications.iterrows()]\n",
43
    "\n",
44
    "# Lab results table\n",
45
    "lab_results = pd.DataFrame({\n",
46
    "    'lab_result_id': np.arange(1, num_rows + 1),\n",
47
    "    'patient_id': patients['patient_id'],\n",
48
    "    'lab_test': np.random.choice(['Lab Test A', 'Lab Test B', 'Lab Test C', 'Lab Test D', 'Lab Test E'], num_rows),\n",
49
    "    'result_value': np.random.uniform(100, 300, num_rows),\n",
50
    "    'result_date': [pd.date_range(row['admission_date'], row['discharge_date'])[np.random.randint(0, len(pd.date_range(row['admission_date'], row['discharge_date']))) - 1] for index, row in patients.iterrows()]\n",
51
    "})\n",
52
    "\n",
53
    "# Readmission risk table\n",
54
    "readmission_risk = pd.DataFrame({\n",
55
    "    'patient_id': patients['patient_id'],\n",
56
    "    'readmission_risk': np.random.choice([0, 1], num_rows)\n",
57
    "})\n",
58
    "\n",
59
    "# Save data to CSV files\n",
60
    "patients.to_csv('patients2.csv', index=False)\n",
61
    "diagnoses.to_csv('diagnoses2.csv', index=False)\n",
62
    "medications.to_csv('medications2.csv', index=False)\n",
63
    "lab_results.to_csv('lab_results2.csv', index=False)\n",
64
    "readmission_risk.to_csv('readmission_risk2.csv', index=False)"
65
   ]
66
  }
67
 ],
68
 "metadata": {
69
  "kernelspec": {
70
   "display_name": "Python 3 (ipykernel)",
71
   "language": "python",
72
   "name": "python3"
73
  },
74
  "language_info": {
75
   "codemirror_mode": {
76
    "name": "ipython",
77
    "version": 3
78
   },
79
   "file_extension": ".py",
80
   "mimetype": "text/x-python",
81
   "name": "python",
82
   "nbconvert_exporter": "python",
83
   "pygments_lexer": "ipython3",
84
   "version": "3.9.18"
85
  }
86
 },
87
 "nbformat": 4,
88
 "nbformat_minor": 5
89
}