Skip to content

HTML styling set_precision should take subset #11656

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

Closed
mattilyra opened this issue Nov 20, 2015 · 7 comments
Closed

HTML styling set_precision should take subset #11656

mattilyra opened this issue Nov 20, 2015 · 7 comments
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap

Comments

@mattilyra
Copy link

There's a problem in the way .set_precision currently works as it is being applied to all table cells indiscriminately. For instance a dataframe with means and standard errors cross validated across some parameter values the set_precision will easily hide a lot of detail in the results.

screen shot 2015-11-20 at 12 03 14

The second parameter (2nd index) is not all zeros, they're just values in the range [1e-4, 1e-3]. Also while for the mean columns a precision of 2 is fine, for the standard error 4 might be more appropriate. So having a subset= keyword argument also for .set_precision would be great.

screen shot 2015-11-20 at 12 02 56


code for making the df

import itertools
import pandas as pd
import numpy as np

jobs = itertools.product(['a', 'b', 'c', 'd'], np.arange(1e-4, 1e-3, .0003), range(10))
rows = []
for v, v2, itr in jobs:
    rows.append({'param_1': v, 'param_2': v2, 'iter': itr,
                 'score_1': np.random.randint(0, 100, size=(1,))[0],
                 'score_2': np.random.rand(1, )[0]})
df_multi = pd.DataFrame(rows)
agg = df_multi.groupby(by=['param_1', 'param_2'])[['score_1', 'score_2']].agg(['mean', 'sem'])
@jreback jreback added Bug Visualization plotting Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap and removed Visualization plotting labels Nov 20, 2015
@jreback jreback added this to the 0.18.0 milestone Nov 20, 2015
@jreback
Copy link
Contributor

jreback commented Nov 20, 2015

yep seems reasonable to me..

pull-requests are welcome!

@jreback jreback changed the title HTML styling set_precision should take subset HTML styling set_precision should take subset Nov 20, 2015
@TomAugspurger
Copy link
Contributor

This is a good addition, but might be a bit of work. Right now we

                    {% if c.value is number %}
                        {{c.value|round(precision)}}
                    {% else %}
                        {{c.value}}
                    {% endif %}

c is a dict with {'type', 'value', 'class', 'props', 'selector'} that's built inStyler._translate. The best way is probably to add aprecision` field to that.

@mattilyra
Copy link
Author

I can take this, although I'll probably require some help as I've never looked at the pandas codebase. The above should get me started at least.

@TomAugspurger
Copy link
Contributor

That'd be great if you want to take it. We're releasing 0.17.1 today sometime, so change probably won't make it. All of this stuff is in pandas/core/style.py.

Right now styler.precision is just an int. That will need to be converted to a dict of {column: int}s (but we should still accept a single int meaning "use this precision for everything". Then in the ._translate step you'll need to add that "precision" field to row_es. That part is the messiest / trickiest code, so let me know if you get stuck.

@mattilyra
Copy link
Author

Ok, yeah this certainly won't make it to 0.17.1 in that case. Any thoughts on how the precision would be applied to the index, or should we just leave the index as is?

@TomAugspurger
Copy link
Contributor

I'd say leave index alone, at least to start with. That is all going to get an overhaul before the next release when we add support for styling Indexes.

@jreback jreback modified the milestones: Next Major Release, 0.18.0 Feb 13, 2016
@TomAugspurger TomAugspurger added the Code Style Code style, linting, code_checks label Mar 11, 2016
@TomAugspurger TomAugspurger removed the Code Style Code style, linting, code_checks label May 17, 2016
@mroeschke mroeschke removed Output-Formatting __repr__ of pandas objects, to_string good first issue labels Apr 21, 2021
@attack68
Copy link
Contributor

attack68 commented Sep 9, 2021

this method is depecated and solutions are now available with Styler.format(precision)

@attack68 attack68 closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants