<jupyter_start><jupyter_text>Amazon SageMaker Data Wrangler demo Data sourceThis demo of Amazon SageMaker Data Wrangler is using [UCI diabetic patient readmission dataset](https://archive.ics.uci.edu/ml/datasets/diabetes+130-us+hospitals+for+years+1999-2008). The dataset represents 10 years (1999-2008) of clinical care at 130 US hospitals and integrated delivery networks. It includes over 50 features representing patient and hospital outcomes. Detail description of the dataset is available in     Detailed description of all the atrributes is provided in Table 1 Beata Strack, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, and <NAME>, “Impact of HbA1c Measurement on Hospital Readmission Rates: Analysis of 70,000 Clinical Database Patient Records,” BioMed Research International, vol. 2014, Article ID 781670, 11 pages, 2014.<jupyter_code>import boto3
import sagemaker

sess = sagemaker.Session()
bucket = sess.default_bucket()
prefix = 'sagemaker/demo-diabetic-datawrangler'

s3_client = boto3.client("s3")
%%sh
wget https://archive.ics.uci.edu/ml/machine-learning-databases/00296/dataset_diabetes.zip
unzip dataset_diabetes.zip<jupyter_output><empty_output><jupyter_text>Split the data for demo purposes<jupyter_code>import pandas as pd
df = pd.read_csv('dataset_diabetes/diabetic_data.csv', index_col = 'encounter_id')
df.head()
demographic_feature_columns = 'patient_nbr,race,gender,age,weight'.split(',')
hospital_visits_feature_columns = 'patient_nbr,admission_type_id,discharge_disposition_id,admission_source_id,time_in_hospital,payer_code,medical_specialty,num_lab_procedures,num_procedures,num_medications,number_outpatient,number_emergency,number_inpatient,diag_1,diag_2,diag_3,readmitted'.split(',')
labs_feature_columns = 'patient_nbr,A1Cresult,max_glu_serum'.split(',')
medication_feature_columns = 'patient_nbr,metformin,repaglinide,nateglinide,chlorpropamide,glimepiride,acetohexamide,glipizide,glyburide,tolbutamide,pioglitazone,rosiglitazone,acarbose,miglitol,troglitazone,tolazamide,examide,citoglipton,insulin,glyburide-metformin,glipizide-metformin,glimepiride-pioglitazone,metformin-rosiglitazone,metformin-pioglitazone,change,diabetesMed'.split(',')<jupyter_output><empty_output><jupyter_text>Split the CSV into multiple CSVs and upload them to a S3 bucket<jupyter_code>dfs = []
suffix = ['demographic', 'hospital_visits', 'labs', 'medication']
for i, columns in enumerate([demographic_feature_columns, hospital_visits_feature_columns, 
                             labs_feature_columns, medication_feature_columns]):
    df_tmp = df[columns]
    print(columns)
    df_tmp.head()
    dfs.append(df_tmp)
    fname = 'dataset_diabetes/diabetic_data_%s.csv' % suffix[i]
    df_tmp.to_csv(fname)
    s3_client.upload_file(fname, bucket,  '%s/%s' % (prefix, fname))
print('Your data is uploaded to s3://%s/%s/' % (bucket, prefix))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1038915913829048, 'fraction_numerical': 0.022585128561501043, 'mean_word_length': 7.804281345565749, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '91470', 'license': 'MIT-0', 'n_tokens_mistral': 1046, 'n_tokens_neox': 953, 'n_words': 185, 'path': 'datawrangler_workshop_pre_requisite.ipynb', 'repo_name': 'aws-samples/amazon-sagemaker-data-wrangler-hospital-readmission-prediction', 'size': '2934'}