@@ -51,15 +51,15 @@ def get_flu_cat(dx):
5151 if dx .startswith (prefix ):
5252 return 1
5353 for i in range (12 , 19 ):
54- prefix = "J{}" . format ( i )
54+ prefix = f "J{ i } "
5555 if dx .startswith (prefix ):
5656 return 2
5757 for i in range (0 , 7 ):
58- prefix = "J0{}" . format ( i )
58+ prefix = f "J0{ i } "
5959 if dx .startswith (prefix ):
6060 return 3
6161 for i in range (20 , 23 ):
62- prefix = "J{}" . format ( i )
62+ prefix = f "J{ i } "
6363 if dx .startswith (prefix ):
6464 return 3
6565 for prefix in ["J40" , "R05" , "H669" , "R509" , "B9789" ]:
@@ -79,7 +79,7 @@ def get_field(row, column):
7979
8080 def row2flu (row ):
8181 for i in range (1 , 9 ):
82- dx = get_field (row , "dx{}" . format ( i ) )
82+ dx = get_field (row , f "dx{ i } " )
8383 flu_cat = get_flu_cat (dx )
8484 if flu_cat is not None :
8585 return flu_cat
@@ -136,7 +136,7 @@ def get_country_mapping():
136136
137137
138138def 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" )
140140 dst_path = os .path .join (TARGET_DIR , target_name )
141141
142142 src_csv = open (src_path , encoding = "utf-8-sig" )
@@ -231,10 +231,10 @@ def state2region_csv():
231231
232232def write_afhsb_csv (period ):
233233 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" ))
235235
236236 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 :
238238 writer = csv .DictWriter (csvfile , fieldnames = fieldnames )
239239 writer .writeheader ()
240240
@@ -248,7 +248,7 @@ def write_afhsb_csv(period):
248248 for flu in sorted (dmisid_dict .keys ()):
249249 visit_sum = dmisid_dict [flu ]
250250 i += 1
251- epiweek = int ("{}{ :02d}". format ( year , week ) )
251+ epiweek = int (f" { year } { week :02d} " )
252252 flu_type = flu_mapping [flu ]
253253
254254 row = {
@@ -290,8 +290,8 @@ def dmisid_start_time():
290290
291291
292292def 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" )
295295
296296 # Load data into a dictionary
297297 src_csv = open (src_path )
@@ -352,7 +352,7 @@ def fillin_zero_to_csv(period, dmisid_start_record):
352352 if i % 100000 == 0 :
353353 print (row )
354354 i += 1
355- print ("Wrote {} rows" . format ( i ) )
355+ print (f "Wrote { i } rows" )
356356
357357
358358######################### Functions for AFHSB data ##########################
0 commit comments