|
a |
|
b/ClinicalTrialMap.py |
|
|
1 |
# install all the packages |
|
|
2 |
import requests |
|
|
3 |
from bs4 import BeautifulSoup |
|
|
4 |
from pyzipcode import ZipCodeDatabase |
|
|
5 |
import folium |
|
|
6 |
import pandas as pd |
|
|
7 |
import matplotlib.pyplot as plt |
|
|
8 |
import numpy as np |
|
|
9 |
|
|
|
10 |
clin_addresses = pd.read_excel("/Users/shania/PycharmProjects/ClinicalAttritionRateMap/final_table.csv") |
|
|
11 |
ruca_codes = pd.read_excel("2006 Complete Excel RUCA file 3.xls") |
|
|
12 |
|
|
|
13 |
valid_zip_codes = [] |
|
|
14 |
for index in ruca_codes.index: |
|
|
15 |
ruca_value = ruca_codes.loc[index, 'RUCA2.0'] # accessing RUCA2.0 |
|
|
16 |
if ruca_value in [7.0, 7.2, 7.3, 7.4, 8.0, 8.2, 8.3, 8.4, 9.0, 9.1, 9.2, 10.0, 10.2, 10.3, 10.4, 10.5, 10.6]: |
|
|
17 |
valid_zip_codes.append(ruca_codes.loc[index, 'ZIPA']) |
|
|
18 |
valid_zip_codes = set(valid_zip_codes) |
|
|
19 |
|
|
|
20 |
zcdb = ZipCodeDatabase() |
|
|
21 |
center_map = folium.Map(location=[39.8283, -98.5795], zoom_start=8) # google the center of the US |
|
|
22 |
|
|
|
23 |
for index in clin_addresses.index: |
|
|
24 |
zip_code = str(clin_addresses.loc[index, 'zip']) |
|
|
25 |
if '-' in zip_code: |
|
|
26 |
zipcode_formatted = zip_code.split('-')[0] # splitting the zipcode if in the #####-#### |
|
|
27 |
print(zipcode_formatted) |
|
|
28 |
else: |
|
|
29 |
print("Unable to provide location for this clinical trial") |
|
|
30 |
continue # skip to the next zipcode |
|
|
31 |
|
|
|
32 |
location_name = clin_addresses.loc[index, 'location_name'] # grab the info I want |
|
|
33 |
nct_id = clin_addresses.loc[index, 'nct_id'] |
|
|
34 |
dropout_rate = clin_addresses.loc[index, 'dropout_percentage_all'] |
|
|
35 |
phase = clin_addresses.loc[index, 'phase'] |
|
|
36 |
study_type = clin_addresses.loc[index, 'study_type'] |
|
|
37 |
|
|
|
38 |
try: |
|
|
39 |
location = zcdb[zipcode_formatted] |
|
|
40 |
lon = location.longitude |
|
|
41 |
lat = location.latitude |
|
|
42 |
coordinates = [lat, lon] |
|
|
43 |
folium.Marker( |
|
|
44 |
location=coordinates, # grab items for the pop-up |
|
|
45 |
popup=f"{location_name}\nNCT ID: {nct_id}\nDropout Rate: {dropout_rate}\nPhase: {phase}\nStudy Type: {study_type}" |
|
|
46 |
).add_to(center_map) |
|
|
47 |
except KeyError: |
|
|
48 |
print(f"Couldn't find zipcode: '{zipcode_formatted}'") |
|
|
49 |
|
|
|
50 |
center_map.save('map-clinical_trials.html') |