@@ -165,7 +165,7 @@ def default_display_func(x):
165
165
if self .na_rep is not None and pd .isna (x ):
166
166
return self .na_rep
167
167
elif is_float (x ):
168
- display_format = "{0 :.{precision}f}". format ( x , precision = self . precision )
168
+ display_format = f" { x :.{self . precision }f} "
169
169
return display_format
170
170
else :
171
171
return x
@@ -293,7 +293,7 @@ def format_attr(pair):
293
293
name = self .data .columns .names [r ]
294
294
cs = [
295
295
BLANK_CLASS if name is None else INDEX_NAME_CLASS ,
296
- "level{lvl}" . format ( lvl = r ) ,
296
+ f "level{ r } " ,
297
297
]
298
298
name = BLANK_VALUE if name is None else name
299
299
row_es .append (
@@ -310,8 +310,8 @@ def format_attr(pair):
310
310
for c , value in enumerate (clabels [r ]):
311
311
cs = [
312
312
COL_HEADING_CLASS ,
313
- "level{lvl}" . format ( lvl = r ) ,
314
- "col{col}" . format ( col = c ) ,
313
+ f "level{ r } " ,
314
+ f "col{ c } " ,
315
315
]
316
316
cs .extend (
317
317
cell_context .get ("col_headings" , {}).get (r , {}).get (c , [])
@@ -339,7 +339,7 @@ def format_attr(pair):
339
339
index_header_row = []
340
340
341
341
for c , name in enumerate (self .data .index .names ):
342
- cs = [INDEX_NAME_CLASS , "level{lvl}" . format ( lvl = c ) ]
342
+ cs = [INDEX_NAME_CLASS , f "level{ c } " ]
343
343
name = "" if name is None else name
344
344
index_header_row .append (
345
345
{"type" : "th" , "value" : name , "class" : " " .join (cs )}
@@ -358,8 +358,8 @@ def format_attr(pair):
358
358
for c , value in enumerate (rlabels [r ]):
359
359
rid = [
360
360
ROW_HEADING_CLASS ,
361
- "level{lvl}" . format ( lvl = c ) ,
362
- "row{row}" . format ( row = r ) ,
361
+ f "level{ c } " ,
362
+ f "row{ r } " ,
363
363
]
364
364
es = {
365
365
"type" : "th" ,
@@ -377,7 +377,7 @@ def format_attr(pair):
377
377
row_es .append (es )
378
378
379
379
for c , col in enumerate (self .data .columns ):
380
- cs = [DATA_CLASS , "row{row}" . format ( row = r ), "col{col}" . format ( col = c ) ]
380
+ cs = [DATA_CLASS , f "row{ r } " , f "col{ c } " ]
381
381
cs .extend (cell_context .get ("data" , {}).get (r , {}).get (c , []))
382
382
formatter = self ._display_funcs [(r , c )]
383
383
value = self .data .iloc [r , c ]
@@ -399,12 +399,7 @@ def format_attr(pair):
399
399
props .append (x .split (":" ))
400
400
else :
401
401
props .append (["" , "" ])
402
- cellstyle .append (
403
- {
404
- "props" : props ,
405
- "selector" : "row{row}_col{col}" .format (row = r , col = c ),
406
- }
407
- )
402
+ cellstyle .append ({"props" : props , "selector" : f"row{ r } _col{ c } " })
408
403
body .append (row_es )
409
404
410
405
table_attr = self .table_attributes
@@ -971,9 +966,7 @@ def hide_columns(self, subset):
971
966
972
967
@staticmethod
973
968
def _highlight_null (v , null_color ):
974
- return (
975
- "background-color: {color}" .format (color = null_color ) if pd .isna (v ) else ""
976
- )
969
+ return f"background-color: { null_color } " if pd .isna (v ) else ""
977
970
978
971
def highlight_null (self , null_color = "red" ):
979
972
"""
@@ -1126,9 +1119,7 @@ def relative_luminance(rgba):
1126
1119
def css (rgba ):
1127
1120
dark = relative_luminance (rgba ) < text_color_threshold
1128
1121
text_color = "#f1f1f1" if dark else "#000000"
1129
- return "background-color: {b};color: {c};" .format (
1130
- b = colors .rgb2hex (rgba ), c = text_color
1131
- )
1122
+ return f"background-color: { colors .rgb2hex (rgba )} ;color: { text_color } ;"
1132
1123
1133
1124
if s .ndim == 1 :
1134
1125
return [css (rgba ) for rgba in rgbas ]
@@ -1160,7 +1151,7 @@ def set_properties(self, subset=None, **kwargs):
1160
1151
>>> df.style.set_properties(color="white", align="right")
1161
1152
>>> df.style.set_properties(**{'background-color': 'yellow'})
1162
1153
"""
1163
- values = ";" .join ("{p}: {v}" . format ( p = p , v = v ) for p , v in kwargs .items ())
1154
+ values = ";" .join (f "{ p } : { v } " for p , v in kwargs .items ())
1164
1155
f = lambda x : values
1165
1156
return self .applymap (f , subset = subset )
1166
1157
@@ -1191,12 +1182,9 @@ def css_bar(start, end, color):
1191
1182
if end > start :
1192
1183
css += "background: linear-gradient(90deg,"
1193
1184
if start > 0 :
1194
- css += " transparent {s:.1f}%, {c} {s:.1f}%, " .format (
1195
- s = start , c = color
1196
- )
1197
- css += "{c} {e:.1f}%, transparent {e:.1f}%)" .format (
1198
- e = min (end , width ), c = color
1199
- )
1185
+ css += f" transparent { start :.1f} %, { color } { start :.1f} %, "
1186
+ e = min (end , width )
1187
+ css += f"{ color } { e :.1f} %, transparent { e :.1f} %)"
1200
1188
return css
1201
1189
1202
1190
def css (x ):
@@ -1358,7 +1346,7 @@ def _highlight_extrema(data, color="yellow", max_=True):
1358
1346
"""
1359
1347
Highlight the min or max in a Series or DataFrame.
1360
1348
"""
1361
- attr = "background-color: {0}" . format ( color )
1349
+ attr = f "background-color: { color } "
1362
1350
1363
1351
if max_ :
1364
1352
extrema = data == np .nanmax (data .to_numpy ())
@@ -1528,16 +1516,13 @@ def _maybe_wrap_formatter(formatter, na_rep: Optional[str]):
1528
1516
elif callable (formatter ):
1529
1517
formatter_func = formatter
1530
1518
else :
1531
- msg = (
1532
- "Expected a template string or callable, got {formatter} "
1533
- "instead" .format (formatter = formatter )
1534
- )
1519
+ msg = f"Expected a template string or callable, got { formatter } instead"
1535
1520
raise TypeError (msg )
1536
1521
1537
1522
if na_rep is None :
1538
1523
return formatter_func
1539
1524
elif isinstance (na_rep , str ):
1540
1525
return lambda x : na_rep if pd .isna (x ) else formatter_func (x )
1541
1526
else :
1542
- msg = "Expected a string, got {na_rep} instead" . format ( na_rep = na_rep )
1527
+ msg = f "Expected a string, got { na_rep } instead"
1543
1528
raise TypeError (msg )
0 commit comments