@@ -51,15 +51,15 @@ def get_flu_cat(dx):
51
51
if dx .startswith (prefix ):
52
52
return 1
53
53
for i in range (12 , 19 ):
54
- prefix = "J{}" . format ( i )
54
+ prefix = f "J{ i } "
55
55
if dx .startswith (prefix ):
56
56
return 2
57
57
for i in range (0 , 7 ):
58
- prefix = "J0{}" . format ( i )
58
+ prefix = f "J0{ i } "
59
59
if dx .startswith (prefix ):
60
60
return 3
61
61
for i in range (20 , 23 ):
62
- prefix = "J{}" . format ( i )
62
+ prefix = f "J{ i } "
63
63
if dx .startswith (prefix ):
64
64
return 3
65
65
for prefix in ["J40" , "R05" , "H669" , "R509" , "B9789" ]:
@@ -79,7 +79,7 @@ def get_field(row, column):
79
79
80
80
def row2flu (row ):
81
81
for i in range (1 , 9 ):
82
- dx = get_field (row , "dx{}" . format ( i ) )
82
+ dx = get_field (row , f "dx{ i } " )
83
83
flu_cat = get_flu_cat (dx )
84
84
if flu_cat is not None :
85
85
return flu_cat
@@ -136,7 +136,7 @@ def get_country_mapping():
136
136
137
137
138
138
def format_dmisid_csv (filename , target_name ):
139
- src_path = os .path .join (TARGET_DIR , "{ }.csv". format ( filename ) )
139
+ src_path = os .path .join (TARGET_DIR , f" { filename } .csv" )
140
140
dst_path = os .path .join (TARGET_DIR , target_name )
141
141
142
142
src_csv = open (src_path , encoding = "utf-8-sig" )
@@ -231,10 +231,10 @@ def state2region_csv():
231
231
232
232
def write_afhsb_csv (period ):
233
233
flu_mapping = {0 : "ili-flu3" , 1 : "flu1" , 2 : "flu2-flu1" , 3 : "flu3-flu2" }
234
- results_dict = pickle .load (open (os .path .join (TARGET_DIR , "{ }.pickle". format ( period ) ), "rb" ))
234
+ results_dict = pickle .load (open (os .path .join (TARGET_DIR , f" { period } .pickle" ), "rb" ))
235
235
236
236
fieldnames = ["id" , "epiweek" , "dmisid" , "flu_type" , "visit_sum" ]
237
- with open (os .path .join (TARGET_DIR , "{ }.csv". format ( period ) ), "w" ) as csvfile :
237
+ with open (os .path .join (TARGET_DIR , f" { period } .csv" ), "w" ) as csvfile :
238
238
writer = csv .DictWriter (csvfile , fieldnames = fieldnames )
239
239
writer .writeheader ()
240
240
@@ -248,7 +248,7 @@ def write_afhsb_csv(period):
248
248
for flu in sorted (dmisid_dict .keys ()):
249
249
visit_sum = dmisid_dict [flu ]
250
250
i += 1
251
- epiweek = int ("{}{ :02d}". format ( year , week ) )
251
+ epiweek = int (f" { year } { week :02d} " )
252
252
flu_type = flu_mapping [flu ]
253
253
254
254
row = {
@@ -290,8 +290,8 @@ def dmisid_start_time():
290
290
291
291
292
292
def fillin_zero_to_csv (period , dmisid_start_record ):
293
- src_path = os .path .join (TARGET_DIR , "{ }.csv". format ( period ) )
294
- dst_path = os .path .join (TARGET_DIR , "filled_{}.csv" . format ( period ) )
293
+ src_path = os .path .join (TARGET_DIR , f" { period } .csv" )
294
+ dst_path = os .path .join (TARGET_DIR , f "filled_{ period } .csv" )
295
295
296
296
# Load data into a dictionary
297
297
src_csv = open (src_path )
@@ -352,7 +352,7 @@ def fillin_zero_to_csv(period, dmisid_start_record):
352
352
if i % 100000 == 0 :
353
353
print (row )
354
354
i += 1
355
- print ("Wrote {} rows" . format ( i ) )
355
+ print (f "Wrote { i } rows" )
356
356
357
357
358
358
######################### Functions for AFHSB data ##########################
0 commit comments