Skip to content

BUG: Styler format na_rep arg overwrites existing when not given. #40032

Closed
@attack68

Description

@attack68

Styler has its own format() method that sets a formatter for columns, and a function set_na_rep() for dealing with missing data.
It seems the two do not play well together:

df = pd.DataFrame([[1,2],[3,4]])
df.iloc[0,0] = np.nan
df.style.set_na_rep('MISS').set_precision(1)

MISS | 2
3.0 | 4

df.style.set_na_rep('MISS').format('{:,.1f}')

nan | 2.0
3.0 | 4.0

df.style.set_na_rep('MISS').format('{:,.1f}', na_rep='PASS')

PASS | 2.0
3.0 | 4.0

could probably do with a review how the attribute na_rep interacts with the formatter and try to make it more dynamic or use pointers instead of static value, if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions