ENH: Add built-in function for Styler to format the text displayed for missing values by immaxchen · Pull Request #29118 · pandas-dev/pandas (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomAugspurger, I like the name format_na
! and yes, I was intended to make an overwriting implementation. Actually, I have considered the set_*
approach as you, but it seems confusing for the case:
df.style.format('{:.2%}').set_na_format('-') # got 'nan%' instead of '-'
I've got a new idea, how about interface like this?
.format_na('-', subset=['col1','col2'])
.format('{:.2%}', na_rep='-', subset=['col3','col4'])
And the docstring for format_na
rephrase to:
Format the text display value using default formatter but represent nan as `na_rep`.
For more advanced formatting, use Styler.format() with your custom formatter.