<jupyter_start><jupyter_text>Patient Examples: Plotting Urine and Dosage TrendsIn this notebook we will go through plotting some examples of patients that have upward or downward trends in Urine Concentration and Dosage. The main takeaway from this notebook: how to parse the csv file and plot a select sample of patients. Steps* Import libraries* Filter for the specified patients* Select the relevent columns for Urine and Dosage* Plot the patients using matplotlib<jupyter_code>import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Load dataframe
DATA_DIR = '../data'
dataset = os.path.join(DATA_DIR, 'dta_file_converted.csv')

df = pd.read_csv(dataset, low_memory=False)
df.head()<jupyter_output><empty_output><jupyter_text>Patient with Clear Upward/Downward TrendsFor simplicity we will use `ices_caseid` as the key, all indices have been converted.|          | Urine    | Dosage ||----------|----------|----------|| Downward |  100027  100029 100057 100109 100169 | 100001 032-0024 032-0087 || Upward   |  100050  |  032-0090 032-0121<jupyter_code># Specific Users selected by Group A and Group B

urine_down = '100027 100029 100057 100109 100169'.split()
urine_up = '100050'.split()

dosage_down = '100001 032-0024 032-0087'.split()
dosage_up = '032-0090 032-0121'.split()

print("Urine Downtrend: {}".format(urine_down))
print("Urine Uptrend: {}".format(urine_up))
print("Dosage Downtrend: {}".format(dosage_down))
print("Dosage Uptrend: {}".format(dosage_up))
# Columns for tracking Urine and Dosage

urine_col = ['ices_caseid',
             'ices_amountdose',
             'ices_currdose3', 
             'ices_currdose6', 
             'ices_currdose9', 
             'ices_currdose12']

dosage_col = ['ices_caseid', 
              'ices_opioidbase',
              'ices_opioid3', 
              'ices_opioid6', 
              'ices_opioid9', 
              'ices_opioid12']

# Separate dataframes by feature and trend

df_urine_down = df.loc[df.ices_caseid.isin(urine_down), urine_col]
df_urine_up = df.loc[df.ices_caseid.isin(urine_up), urine_col]

df_dosage_down = df.loc[df.ices_caseid.isin(dosage_down), dosage_col]
df_dosage_up = df.loc[df.ices_caseid.isin(dosage_up), dosage_col]<jupyter_output><empty_output><jupyter_text>Plot Patient Examples<jupyter_code># These are the columns used to label x-axis and y-axis

x_urine_cols = ['Base', '3 M', '6 M', '9 M', '12 M']
y_urine_cols = 'ices_amountdose ices_currdose3 ices_currdose6 ices_currdose9 ices_currdose12'.split()

x_dosage_cols = x_urine_cols
y_dosage_cols = ['ices_opioidbase','ices_opioid3', 'ices_opioid6', 'ices_opioid9', 'ices_opioid12']
fig,ax = plt.subplots(figsize=(10,6))

# Iterate through the dataframe and plot each row
for row in df_urine_down.iterrows():
    data = row[1]
    ax.scatter(x=x_urine_cols, y=data[y_urine_cols], label=data['ices_caseid'])

ax.legend()
ax.set_title('URINE - Downward Patient Examples')
ax.set_xlabel('Time')
ax.set_ylabel('Urine')
fig,ax = plt.subplots(figsize=(10,6))

for row in df_urine_up.iterrows():
    data = row[1]
    ax.scatter(x=x_urine_cols, y=data[y_urine_cols], label=data['ices_caseid'])

ax.legend()
ax.set_title('URINE - Upward Patient Examples')
ax.set_xlabel('Time')
ax.set_ylabel('Urine')
fig,ax = plt.subplots(figsize=(10,6))

for row in df_dosage_down.iterrows():
    data = row[1]
    ax.scatter(x=x_dosage_cols, y=data[y_dosage_cols], label=data['ices_caseid'])

ax.legend()
ax.set_title('DOSAGE - Downward Patient Examples')
ax.set_xlabel('Time')
ax.set_ylabel('Dosage')
fig,ax = plt.subplots(figsize=(10,6))

for row in df_dosage_up.iterrows():
    data = row[1]
    ax.scatter(x=x_dosage_cols, y=data[y_dosage_cols], label=data['ices_caseid'])

ax.legend()
ax.set_title('DOSAGE - Upward Patient Examples')
ax.set_xlabel('Time')
ax.set_ylabel('Dosage')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13018672199170125, 'fraction_numerical': 0.046939834024896265, 'mean_word_length': 4.7310549777117386, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '118445', 'license': 'MIT', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1427, 'n_words': 314, 'path': 'notebooks/patient_examples_notebook/patient_examples.ipynb', 'repo_name': 'McMasterAI/POST_study_Project', 'size': '3856'}