-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch.py
397 lines (317 loc) · 27.2 KB
/
fetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import numpy as np
import pandas as pd
def parse_date(date):
"""Convert date to datetime with handling for Excel date numbers"""
try:
date = int(date)
return pd.to_datetime('1899-12-30') + pd.to_timedelta(date, 'D')
except:
return pd.to_datetime(date[0:10])
def fix_date_index(df):
"""Convert date index strings to datetime objects"""
date_index = df.index.levels[2].to_series()
date_index_fixed = date_index.apply(parse_date) + pd.DateOffset(1)
df.index = df.index.set_levels(date_index_fixed, level=2)
def generate_date_range(index):
"""Generate DatetimeIndex using first and last dates from index column"""
if type(index[0]) == str:
start = parse_date(index[0].split(" ")[-1])
end = parse_date(index[-1].split(" ")[-1])
else:
start = index[0]
end = index[-1]
return pd.date_range(start=start, end=end)
tsa_county_map = {
'A': ['Armstrong', 'Briscoe', 'Carson', 'Childress', 'Collingsworth', 'Dallam', 'Deaf Smith',
'Donley', 'Gray', 'Hall', 'Hansford', 'Hartley', 'Hemphill', 'Hutchinson', 'Lipscomb',
'Moore', 'Ochiltree', 'Oldham', 'Parmer', 'Potter', 'Randall', 'Roberts', 'Sherman',
'Swisher', 'Wheeler'],
'B': ['Bailey', 'Borden', 'Castro', 'Cochran', 'Cottle', 'Crosby', 'Dawson', 'Dickens', 'Floyd',
'Gaines', 'Garza', 'Hale', 'Hockley', 'Kent', 'King', 'Lamb', 'Lubbock', 'Lynn', 'Motley',
'Scurry', 'Terry', 'Yoakum'],
'C': ['Archer', 'Baylor', 'Clay', 'Foard', 'Hardeman', 'Jack', 'Montague', 'Wichita', 'Wilbarger', 'Young'],
'D': ['Brown', 'Callahan', 'Coleman', 'Comanche', 'Eastland', 'Fisher', 'Haskell', 'Jones',
'Knox', 'Mitchell', 'Nolan', 'Shackelford', 'Stephens', 'Stonewall', 'Taylor', 'Throckmorton'],
'E': ['Collin', 'Cooke', 'Dallas', 'Denton', 'Ellis', 'Erath', 'Fannin', 'Grayson', 'Hood',
'Hunt', 'Johnson', 'Kaufman', 'Navarro', 'Palo Pinto', 'Parker', 'Rockwall',
'Somervell', 'Tarrant', 'Wise'],
'F': ['Bowie', 'Cass', 'Delta', 'Hopkins', 'Lamar', 'Morris', 'Red River', 'Titus'],
'G': ['Anderson', 'Camp', 'Cherokee', 'Franklin', 'Freestone', 'Gregg', 'Harrison', 'Henderson',
'Houston', 'Marion', 'Panola', 'Rains', 'Rusk', 'Shelby', 'Smith', 'Trinity', 'Upshur',
'Van Zandt', 'Wood'],
'H': ['Angelina', 'Nacogdoches', 'Polk', 'Sabine', 'San Augustine', 'San Jacinto', 'Tyler'],
'I': ['Culberson', 'El Paso', 'Hudspeth'],
'J': ['Andrews', 'Brewster', 'Crane', 'Ector', 'Glasscock', 'Howard', 'Jeff Davis', 'Loving',
'Martin', 'Midland', 'Pecos', 'Presidio', 'Reeves', 'Terrell', 'Upton', 'Ward', 'Winkler'],
'K': ['Coke', 'Concho', 'Crockett', 'Irion', 'Kimble', 'Mason', 'Mcculloch', 'Menard', 'Reagan',
'Runnels', 'Schleicher', 'Sterling', 'Sutton', 'Tom Green'],
'L': ['Bell', 'Coryell', 'Hamilton', 'Lampasas', 'Milam', 'Mills'],
'M': ['Bosque', 'Falls', 'Hill', 'Limestone', 'Mclennan'],
'N': ['Brazos', 'Burleson', 'Grimes', 'Leon', 'Madison', 'Robertson', 'Washington'],
'O': ['Bastrop', 'Blanco' ,'Burnet' ,'Caldwell', 'Fayette', 'Hays', 'Lee', 'Llano', 'San Saba',
'Travis', 'Williamson'],
'P': ['Atascosa', 'Bandera', 'Bexar', 'Comal', 'Dimmit', 'Edwards', 'Frio', 'Gillespie',
'Gonzales', 'Guadalupe', 'Karnes', 'Kendall', 'Kerr', 'Kinney', 'La Salle', 'Maverick',
'Medina', 'Real', 'Uvalde', 'Val Verde', 'Wilson', 'Zavala'],
'Q': ['Austin', 'Colorado', 'Fort Bend', 'Harris', 'Matagorda', 'Montgomery', 'Walker', 'Waller', 'Wharton'],
'R': ['Brazoria', 'Chambers', 'Galveston', 'Hardin', 'Jasper', 'Jefferson', 'Liberty', 'Newton', 'Orange'],
'S': ['Calhoun', 'Dewitt', 'De Witt', 'Goliad', 'Jackson', 'Lavaca', 'Victoria'],
'T': ['Jim Hogg', 'Webb', 'Zapata'],
'U': ['Aransas', 'Bee', 'Brooks', 'Duval', 'Jim Wells', 'Kenedy', 'Kleberg', 'Live Oak',
'Mcmullen', 'Nueces', 'Refugio', 'San Patricio'],
'V': ['Cameron', 'Hidalgo', 'Starr', 'Willacy'],
'Total': ['Total', 'Grand Total']
}
def map_county_to_tsa(county):
"""Map county name to TSA"""
for k,v in tsa_county_map.items():
if county.title() in v:
return(k)
# Load combined hospital data
url = 'https://www.dshs.texas.gov/sites/default/files/chs/data/COVID/Combined%20Hospital%20Data%20over%20Time%20by%20TSA%20Region.xlsx'
df = pd.read_excel(url, sheet_name=None, header=2, index_col=[0, 1], nrows=23)
# Parse total available beds
df['Total Available Beds'].replace('--', np.nan, inplace=True)
df['Total Available Beds'] = df['Total Available Beds'].apply(pd.to_numeric)
df['Total Available Beds'].loc['Total', 'Statewide Total'] = df['Total Available Beds'][:-1].sum()
df_total_beds_available = pd.DataFrame(df['Total Available Beds'].stack())
df_total_beds_available.rename(columns = {0: 'total_beds_available'}, inplace=True)
fix_date_index(df_total_beds_available)
# Parse total occupied beds
df['Total Occupied Beds'].replace('--', np.nan, inplace=True)
df['Total Occupied Beds'] = df['Total Occupied Beds'].apply(pd.to_numeric)
df['Total Occupied Beds'].loc['Total', 'Statewide Total'] = df['Total Occupied Beds'][:-1].sum()
df_total_beds_occupied = pd.DataFrame(df['Total Occupied Beds'].stack())
df_total_beds_occupied.rename(columns = {0: 'total_beds_occupied'}, inplace=True)
fix_date_index(df_total_beds_occupied)
# Parse available ICU beds
df['Adult ICU Beds Available'].replace('--', np.nan, inplace=True)
df['Adult ICU Beds Available'] = df['Adult ICU Beds Available'].apply(pd.to_numeric)
df['Adult ICU Beds Available'].loc['Total', 'Statewide Total'] = df['Adult ICU Beds Available'][:-1].sum()
df_icu_beds_available = pd.DataFrame(df['Adult ICU Beds Available'].stack())
df_icu_beds_available.rename(columns = {0: 'icu_beds_available'}, inplace=True)
fix_date_index(df_icu_beds_available)
#Parse occupied ICU beds
df['ICU Beds Occupied'].replace('--', np.nan, inplace=True)
df['ICU Beds Occupied'] = df['ICU Beds Occupied'].apply(pd.to_numeric)
df['ICU Beds Occupied'].loc['Total', 'Statewide Total'] = df['ICU Beds Occupied'][:-1].sum()
df_icu_beds_occupied = pd.DataFrame(df['ICU Beds Occupied'].stack())
df_icu_beds_occupied.rename(columns = {0: 'icu_beds_occupied'}, inplace=True)
fix_date_index(df_icu_beds_occupied)
# Parse total COVID-19 inpatients
df['COVID-19 Hospitalizations'].loc['Total', 'Statewide Total'] = df['COVID-19 Hospitalizations'][:-1].sum()
df_covid_inpatients = pd.DataFrame(df['COVID-19 Hospitalizations'].stack())
df_covid_inpatients.rename(columns = {0: 'covid_inpatients'}, inplace=True)
fix_date_index(df_covid_inpatients)
# Parse ICU COVID-19 inpatients
df['Adult COVID-19 ICU'].loc['Total', 'Statewide Total'] = df['Adult COVID-19 ICU'][:-1].sum()
df_covid_icu_inpatients = pd.DataFrame(df['Adult COVID-19 ICU'].stack())
df_covid_icu_inpatients.rename(columns = {0: 'covid_icu_inpatients'}, inplace=True)
fix_date_index(df_covid_icu_inpatients)
# Load and parse total case count data
url = 'https://www.dshs.texas.gov/sites/default/files/chs/data/COVID/Texas%20COVID-19%20Cumulative%20Confirmed%20Cases%20by%20County.xlsx'
df = pd.read_excel(url, sheet_name=None, index_col=[0], header=2, nrows=256)
df = pd.concat(df, axis=1).droplevel(0, axis=1)
df.drop(columns=["Unknown Date", "Total", "2020 Total"], inplace=True)
df.columns = generate_date_range(df.columns)
df = df.loc[:, df.columns > '2020-04-11']
df.insert(0, 'TSA ID', [map_county_to_tsa(county) for county in df.index])
df = df.groupby(['TSA ID']).sum()
tsa_location_map = dict(zip(df_total_beds_available.index.get_level_values(0).drop_duplicates(),
df_total_beds_available.index.get_level_values(1).drop_duplicates()))
df['TSA AREA'] = [tsa_location_map[tsa] for tsa in df.index]
df.set_index('TSA AREA', append=True, inplace=True)
df_cases = pd.DataFrame(df.stack())
df_cases.rename(columns = {0: 'cases'}, inplace=True)
# Load and parse daily case count data
url = 'https://www.dshs.texas.gov/sites/default/files/chs/data/COVID/Texas%20COVID-19%20New%20Confirmed%20Cases%20by%20County.xlsx'
df = pd.read_excel(url, sheet_name=None, index_col=[0], header=2, nrows=256)
df = pd.concat(df, axis=1).droplevel(0, axis=1)
df.drop(columns=["Unknown Date", "Total", "Total 2021"], inplace=True)
df.columns = generate_date_range(df.columns)
df = df.loc[:, df.columns > '2020-04-11']
df.insert(0, 'TSA ID', [map_county_to_tsa(county) for county in df.index])
df = df.groupby(['TSA ID']).sum()
df['TSA AREA'] = [tsa_location_map[tsa] for tsa in df.index]
df.set_index('TSA AREA', append=True, inplace=True)
df_cases_new = pd.DataFrame(df.stack())
df_cases_new.rename(columns = {0: 'cases_new'}, inplace=True)
# Load and parse total death data
url = 'https://www.dshs.texas.gov/sites/default/files/chs/data/COVID/Texas%20COVID-19%20Fatality%20Count%20Data%20by%20County.xlsx'
df = pd.read_excel(url, sheet_name=None, index_col=[0], header=2, nrows=256)
df = pd.concat(df, axis=1).droplevel(0, axis=1)
new_date_range = generate_date_range(df.columns)
df.columns = new_date_range
df_new = df.diff(axis=1) # Extract daily death count
df = df.loc[:, df.columns > '2020-04-11']
df.insert(0, 'TSA ID', [map_county_to_tsa(county) for county in df.index])
df = df.groupby(['TSA ID']).sum()
df[df_cases.index.get_level_values(2)[-1]] = df.iloc[:, -1] # Replicate last column to match date extent of case data
df['TSA AREA'] = [tsa_location_map[tsa] for tsa in df.index]
df.set_index('TSA AREA', append=True, inplace=True)
df_deaths = pd.DataFrame(df.stack())
df_deaths.rename(columns = {0: 'deaths'}, inplace=True)
# Parse daily death data
df_new = df_new.loc[:, df_new.columns > '2020-04-11']
df_new.insert(0, 'TSA ID', [map_county_to_tsa(county) for county in df_new.index])
df_new = df_new.groupby(['TSA ID']).sum()
df_new['TSA AREA'] = [tsa_location_map[tsa] for tsa in df_new.index]
df_new.set_index('TSA AREA', append=True, inplace=True)
df_deaths_new = pd.DataFrame(df_new.stack())
df_deaths_new.rename(columns = {0: 'deaths_new'}, inplace=True)
# Merge the datasets
df = [df_total_beds_available, df_total_beds_occupied, df_icu_beds_available,
df_icu_beds_occupied, df_covid_inpatients, df_covid_icu_inpatients,
df_cases, df_cases_new, df_deaths, df_deaths_new]
df_merged = pd.concat(df, join='outer', axis=1).reindex(df_total_beds_available.index)
# Reset the index
df_merged.index.names = ['tsa', 'location', 'date']
df_merged.reset_index(inplace=True)
df_merged['tsa'] = df_merged['tsa'].apply(lambda x: x.replace('.', ''))
# Write unmodified data to CSV file
df_merged.to_csv('data.csv', index=False, float_format='%d', date_format='%Y-%m-%d')
# Manual removals of extreme values
df_merged.loc[(df_merged['tsa'] == 'N') & (df_merged['date'] == '2020-04-28'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-05-15'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'I') & (df_merged['date'] == '2020-05-31'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2020-06-07'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-06-26'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-06-17'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-17'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'B') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-07-23'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'E') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'I') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-23'), ['covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'P') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Q') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'S') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2020-07-23'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-23'), ['total_beds_occupied', 'total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-07-24'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'B') & (df_merged['date'] == '2020-07-24'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2020-07-24'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-07-24'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-07-24'), 'total_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-24'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-07-24'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-24'), 'covid_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2020-07-24'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-24'), ['total_beds_occupied', 'total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-07-25'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2020-07-25'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-07-25'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-07-25'), 'total_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-25'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-07-25'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-25'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-25'), ['total_beds_occupied', 'total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'icu_beds_occupied', 'covid_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-07-26'), ['icu_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'B') & (df_merged['date'] == '2020-07-26'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'E') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'F') & (df_merged['date'] == '2020-07-26'), ['covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'G') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'H') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'I') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'N') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Q') & (df_merged['date'] == '2020-07-26'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'U') & (df_merged['date'] == '2020-07-26'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-26'), ['total_beds_occupied', 'total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'B') & (df_merged['date'] == '2020-07-27'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'H') & (df_merged['date'] == '2020-07-27'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-07-27'), 'total_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-07-27'), 'covid_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-07-27'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-27'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-07-27'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-27'), ['total_beds_occupied', 'total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-07-28'), ['total_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2020-07-28'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-07-28'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'H') & (df_merged['date'] == '2020-07-28'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-28'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-07-28'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-28'), ['total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-07-29'), ['total_beds_occupied', 'covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2020-07-29'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-07-29'), ['total_beds_available', 'icu_beds_available']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-07-31'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Q') & (df_merged['date'] == '2020-07-31'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2020-07-31'), 'covid_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'G') & (df_merged['date'] == '2020-08-01'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-08-01'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'M') & (df_merged['date'] == '2020-08-01'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'U') & (df_merged['date'] == '2020-08-01'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'F') & (df_merged['date'] == '2020-08-02'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'S') & (df_merged['date'] == '2020-08-08'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-08-09'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'P') & (df_merged['date'] == '2020-08-19'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-08-28'), 'total_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'B') & (df_merged['date'] == '2020-09-12'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'P') & (df_merged['date'] == '2020-09-16'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-09-28'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2020-10-09'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2020-10-18'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'K') & (df_merged['date'] == '2020-10-20'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-10-21'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2020-10-28'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Q') & (df_merged['date'] == '2020-11-01'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2020-11-01'), 'covid_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'S') & (df_merged['date'] == '2020-11-02'), 'icu_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'D') & (df_merged['date'] == '2020-11-08'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2020-11-17'), 'icu_beds_available'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'A') & (df_merged['date'] == '2020-11-27'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-12-10'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2020-12-17'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'H') & (df_merged['date'] == '2020-12-18'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2021-01-02'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2021-01-07'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'H') & (df_merged['date'] == '2021-01-08'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2021-01-10'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'G') & (df_merged['date'] == '2021-01-10'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2021-01-10'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'C') & (df_merged['date'] == '2021-01-11'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'G') & (df_merged['date'] == '2021-01-11'), ['total_beds_occupied', 'icu_beds_occupied']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2021-01-11'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2021-01-14'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'F') & (df_merged['date'] == '2021-01-27'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'N') & (df_merged['date'] == '2021-02-01'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2021-05-12'), ['covid_inpatients', 'covid_icu_inpatients']] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2021-06-29'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2021-06-29'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2021-07-12'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2021-07-12'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'T') & (df_merged['date'] == '2021-08-10'), 'cases_new'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'I') & (df_merged['date'] == '2021-11-28'), 'icu_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2022-03-03'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2022-03-04'), 'total_beds_occupied'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Total') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'E') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'G') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'I') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'J') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'L') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'O') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'P') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'Q') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'R') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'S') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'U') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
df_merged.loc[(df_merged['tsa'] == 'V') & (df_merged['date'] == '2022-03-07'), 'covid_icu_inpatients'] = np.nan
# Eliminate negative values from cases_new
df_merged.loc[df_merged['cases_new'] < 0, 'cases_new'] = np.nan
# Write cleaned data to CSV file
df_merged.to_csv('docs/data.csv', index=False, float_format='%d', date_format='%Y-%m-%d')