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

ENH: write Styler rendered output to file #13379

Closed
jorisvandenbossche opened this issue Jun 6, 2016 · 5 comments · Fixed by #40312
Closed

ENH: write Styler rendered output to file #13379

jorisvandenbossche opened this issue Jun 6, 2016 · 5 comments · Fixed by #40312
Labels
Enhancement IO HTML read_html, to_html, Styler.apply, Styler.applymap Styler conditional formatting using DataFrame.style
Milestone

Comments

@jorisvandenbossche
Copy link
Member

I was answering a question on conditional formatting of html on SO.

So the OP was using to_html but wanted conditional formatting. Therefore, I pointed to Styler to do this more easily than using the formatters argument in to_html, but when you have a Styler object, there is no longer a to_html method to write the result to a html file.

Of course you can write the result of render manually to a file, but would this ability be a desired enhancement?

  • Maybe we can add a to_file method to Styler? (to_html seems a bit specific, if we also want to use the Styler for other formats such as latex in the future)
  • Alternatively, we could add a style option in to_html where you can pass a Styler object?

Related to #11610

@TomAugspurger

@jorisvandenbossche jorisvandenbossche added the IO HTML read_html, to_html, Styler.apply, Styler.applymap label Jun 6, 2016
@jreback
Copy link
Contributor

jreback commented Jun 6, 2016

xref to #11700 as well

@TomAugspurger
Copy link
Contributor

Another option is to take a buf_or_file in Styler.render, to match the to_html behavior. +1 to that or a to_file method.

For now I'd say just write the output of .render, but we could eventually add options for writing a standalone document, including other CSS files.

@toobaz
Copy link
Member

toobaz commented Jun 29, 2018

This branch adds a to_html method. I used it a couple of times, but to be honest I don't remember whether it worked fine or had relevant issues.

Maybe we can add a to_file method to Styler? (to_html seems a bit specific, if we also want to use the Styler for other formats such as latex in the future)

I assumed the Styler could just have the output methods that DataFrame itself has.... but indeed this is not a good approach if we plan to massively/cheaply enlarge the number of supported formats, i.e. by relying on external converting libraries.

@jorisvandenbossche
Copy link
Member Author

I assumed the Styler could just have the output methods that DataFrame itself has...

That depends a bit on how we see the Styler (I didn't use it lately, so I can't really remember). Would one Styler object both support to html and to latex, or would you rather have a Styler class for to html and a Styler class for to latex? (as the templates are different, many methods will have to add different syntax, ..)

@toobaz
Copy link
Member

toobaz commented Jun 29, 2018

would you rather have a Styler class for to html and a Styler class for to latex?

I admit I hadn't even considered this option.

as the templates are different, many methods will have to add different syntax

Not sure I understand what a template is. Do you think that, say, the syntax of Style.to_latex should be different from a mere combination of the syntax of Style.to_html and the syntax of DataFrame.to_latex?

In particular, I never thought about having parameters in to_latex map to specific LaTeX formatting commands, because to my eyes not being able to transparently change the backend would defeat the purpose of supporting multiple backends. I rather see a set of supported formatting options which default to CSS ones (with, in the future, some additions if required), and other methods as a translation between CSS "language" and the desired format. Then CSS is huge, so each method would have in the docs a list of attributes it actually supports.

@jbrockmendel jbrockmendel added the Styler conditional formatting using DataFrame.style label Dec 11, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.3 May 21, 2021
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 Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants