# define a list for storing info about each clinic
clinics = []
# loop through each row
for row_index in range(0, len(df.index)):
row = df.iloc[row_index]
if row[0] > 0:
clinic = {}
clinic['Id'] = row[0]
# fix records with missing information, such as city name, phone, etc.
if clinic['Id'] == 55:
df.set_value(row_index + 2, 1, 'Johnson City, TN 37601')
if clinic['Id'] == 542:
df.set_value(row_index + 2, 1, 'Columbia, TN 38401')
if clinic['Id'] == 98:
df.set_value(row_index, 2, 'Medical Director: NA')
if clinic['Id'] in [122, 145, 398, 496, 542, 545, 548, 553, 639, 752]:
df.set_value(row_index + 3, 1, '000-000-0000')
# extract clinic info
clinic['Name'] = row[1]
clinic['MedDirector'] = str(row[2]).split(":")[1].strip()
clinic['FacLicNum'] = row[3].split(":")[1].strip()
clinic['Street'] = df.iloc[row_index + 1][1].strip()
clinic['Status'] = df.iloc[row_index + 1][3].split(":")[1].strip()
clinic['City'] = df.iloc[row_index + 2][1].split(',')[0].strip()
clinic['State'] = df.iloc[row_index + 2][1].split(',')[1].strip().split(' ')[0]
clinic['Zip'] = df.iloc[row_index + 2][1].split(',')[1].strip().split(' ')[1]
clinic['OrgLic'] = df.iloc[row_index + 2][3].split(":")[1].strip()
clinic['Phone'] = df.iloc[row_index + 3][1].strip()
clinic['ExpDate'] = df.iloc[row_index + 3][3].split(":")[1].strip()
clinic['Displinary'] = df.iloc[row_index + 4][3].strip()
clinics.append(clinic)
else:
pass