-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add built-in function for Styler to format the text displayed for missing values #29118
Changes from 2 commits
c42de40
01632ce
53b0843
7a5dd65
da3cb43
bdfff98
b86bdc6
a1e9a9e
def71c9
af396b1
3d4cfd0
bd99db9
346eee6
7935359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,6 +930,25 @@ def hide_columns(self, subset): | |
# A collection of "builtin" styles | ||
# ----------------------------------------------------------------------- | ||
|
||
def format_null(self, na_rep="-"): | ||
""" | ||
Format the text displayed for missing values. | ||
|
||
.. versionadded:: 1.0.0 | ||
|
||
Parameters | ||
---------- | ||
na_rep : str | ||
|
||
Returns | ||
------- | ||
self : Styler | ||
""" | ||
self.format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it will overwrite the formatting of a previously applied formatter for non-NA values. Something like df.style.format("hi-{}".format).format_null() is that the case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @TomAugspurger, I like the name
I've got a new idea, how about interface like this?
And the docstring for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may not have been clear about my concern. It's fine that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about adding an But if we add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, so a setting at the table level: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that sounds correct. I'm not sure what the default should be, but probably just None (no special formatting for NA values). |
||
lambda x: na_rep if pd.isna(x) else self._display_funcs.default_factory()(x) | ||
) | ||
return self | ||
|
||
@staticmethod | ||
def _highlight_null(v, null_color): | ||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u add this into the user guide as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like the name
format_nans
better, to be similar tofillna
,hasnans
etc.@jreback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll be glad to!