-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
WIP: df rendering using templates + conditional formatting for HTML #5763
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
Conversation
cc @takluyver |
I like this - should we prefix the classes Also I'm assuming the default names will be part of the standard pandas repr? Finally are you planning to allow users to get at the underlying Jinja rendering object so they can add in filters to use with their template? That might be overkill though. |
will do on the class name namespacing. Not sure yet whether this API should live on the dataframe object or in it's own namespace. Not sure what you mean by rendering object, but generally speaking sure, if the user wants Also, still pondering whether this belongs in pandas or it's own package. |
You can register template functions with Jinja. I thought you were letting people use their own templates? I'm not clear. |
Yes, you'll be able to pass in an arbitrary template at construction time. But that means you may In the previous attempt, I looked at using mako which supports arbitrary logic in templates, The major use case of HTML/css output with conditional formatting is well-covered and with |
Okay, makes sense - the solution definitely looks good (and I think IPython |
Started arranging code into place, added nb of example usage for dotted API.
|
Add md and latex, abstract class names, template fixes
looking forward to this 👏 |
Another aborted attempt, sorry. Don't know when if ever I'll finish this, |
I have a naive Q.. When I write an HTML table in a markup cell in the notebook, it is being printed just the same as a df.head() table. That made me think that the output of an df.head() operation is an HTML code which is govern by IPython default table styling (perhaps in a CSS file). I thought that in order to change the way df.head() is rendering, all I need is to hack into the IPython CSS file and change the appropriate styling code. Can you explain where I'm wrong? Im curious to know what really happening behind the scenes.. :) |
@edoson I don't think you are wrong. ;-) When you do |
and DataFrame has a so a way of doing this would be to override that display method and do exactly what you want, e.g.
|
@takluyver so to change the appearance of table in IPython notebook, all one needs to do is to override the tables styling of IPython, right? Problem is I dont know where IPython tables styling config is (is it CSS? is it hardcoded?) I have a CSS file with nice styling, I have an HTML file with demo code, but I dont know how to tell IPython to use that style rules. @jreback Is this an alternative why to using CSS's? because if the _repr_html returns an html code of a table, and IPython renders it by its own styling rules, we are in the same place. Or maybe I code return the HTML code I already have which uses nice table styles and have it refer to my custom.css file? Need some more guidance.. :) |
@edoson I am not sure how ipython renders after the HTML is produced. You can pass |
If we have any styling of tables, it's in CSS. You can add CSS to the page by displaying HTML:
|
closes #3190.
Provides conditional formatting and CSS styling of HTML tables for dataframes using code.
The plan is to clean up and package the functionality behind a nice API in some pandas namespace,
perhaps with a dotted API, and ship in 0.14.
Unlike my first attempt from 6 months ago which turned into a rabbit hole, this is a much simpler approach that came together in a few hours and supports everything I care about.
See the ipython notebook in the root directory, or on nbviewer.
Feedback welcome.
(Example: highlight 3 largest values in "price" column for each frame in a panel).