Skip to content
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

Right align numbers in HTML repr of tables #12144

Open
pwaller opened this issue Jan 26, 2016 · 5 comments
Open

Right align numbers in HTML repr of tables #12144

pwaller opened this issue Jan 26, 2016 · 5 comments
Labels
Enhancement IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string Styler conditional formatting using DataFrame.style

Comments

@pwaller
Copy link
Contributor

pwaller commented Jan 26, 2016

Is there a way to right-align numbers in the HTML repr of tables? Right now they are left aligned, and it is a bit of a pain.

I see there is a lot of work on conditional HTML formatting recently (e.g, #10250). Is it already possible to achieve this?

/cc @TomAugspurger

@TomAugspurger
Copy link
Contributor

We haven't hooked up DataFrame._repr_html_ to use the new style class. In the meantime you can either use something like

df = pd.DataFrame(np.random.randn(4, 4))
df

df.style.set_table_styles(
    [{"selector": "td", "props": [("text-align", "right")]}]
).set_precision(2)

To right-align each cell, or inject that css straight into the notebook.

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Jan 26, 2016
@jreback
Copy link
Contributor

jreback commented Jan 26, 2016

add to #11610 the master tracker for this issue

@jreback jreback added this to the Next Major Release milestone Jan 26, 2016
@pwaller
Copy link
Contributor Author

pwaller commented Jan 26, 2016

Awesome, thanks.

@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
@matanox
Copy link

matanox commented Dec 30, 2018

Still works :-)

@attack68 attack68 added the Styler conditional formatting using DataFrame.style label Feb 20, 2021
@astoff
Copy link

astoff commented Sep 28, 2021

I still see this issue in Pandas 1.3.0. Without the additional styling that Jupyter seems to apply, the dataframe pd.DataFrame([[111.1],[2.222]]) renders like this:

image

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

7 participants