-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Provide a template-engine based way of rendering pandas data objects #3190
Comments
@y-p What kind of API are you thinking about here? For 1) existing df.to_html(template='/path/to/template') and 2) New df.to_template(template='/path/to/template') |
Or for 1) just keeping the current API (probably better because of back compat) and "freezing" the keyword parameters (and using them in the template). |
and so on... The style DSL and all the bells and whistles you could put into this make me fear The idea was to use pandas objects as fundamental data containers, let the user I was excited about the prospects but my initial attempt to implement did not end in a system If you drop conditional formating and just provide boilerplate templates for html and latex, which That doesn't cover the value formatters problem ("%3.6f", translate factors levels into labels, etc'). I'm not going to try again for the forseeable future. |
I'm working on this again now. typical. |
@olgabot, can you recommend a few alternatives for colormaps to bake into this? |
Nailed it. claiming this for 0.14. |
If there are any watchers out there who dabble in design and want to sling some css to style |
you might want to consider using df.eval/query parsing machinery (instead of lambdas) |
Reduced scope considerably, beautifully simple now and trivial to implement. |
@y-p I'm always a fan of the simple sequential colormap for counts, like YlGnBu: http://bl.ocks.org/mbostock/5577023 (top, second from left) |
Thanks... just in time :) |
I see you are planning a conditional formatting, that is quite nice but the colors here are quit ugly.. :) what about changes to the default way tables are rendered? see here: http://coding.smashingmagazine.com/2008/08/13/top-10-css-table-designs/ |
Actually Im not interested in conditional formatting of a a dataframe, more interested in changing the default rendering to something more stylish. Do you think someone whould like something like that? |
@cpcloud @TomAugspurger @jorisvandenbossche @hayd anyone able to try this for 0.14? small/experimental is ok |
I'm looking into this. I'd be using a big chunk of what y-p put together in #5763. For the API, what are people's thoughts on something like how d3 does it? (I don't know much d3, but this is my understanding. Hopefully someone knows more) We'd have a method like
This would let you do something like def color_max(val, loc, col):
if val == col.max():
return "#FF0000"
df = pd.DataFrame({'A': [1, 2]})
df.format(style={'background-color': color_max}) For those cells where There are a lot of drawbacks to this approach. It's not the friendliest to functions that want to use locations. Or functions that want to apply an operation to the entire dataframe. It's hard to say without be able to use it. I'll try to get something working. |
An alternative is what y-p had. You define a function that selects part of a table based on CSS attributes: def tag_col(n,c="grey10", with_headings=False):
selector="td.col%d" % n
if not with_headings:
selector+=".data"
return [dict(selector=selector,
props=[("background-color",c)])] I'm still learning all this stuff, so at this point I'm not sure which approach is more flexible. |
I would use a class based approach, e.g. you provide the base class then let users override it e.g.
then
and then can be overriden with a custom class, otherwise or just pass the kwargs in the Formatter. |
Has anybody looked at using ipythonblocks for visualising dataframes? I'm not much of a python coder but I had a stab at getting started using ipython blocks to help visualise merge and reshape operations using pandas dataframes for a data/databases course I'm working on: http://nbviewer.ipython.org/gist/psychemedia/9795643 Related issue on ipythonblocks tracker: jiffyclub/ipythonblocks#29 discussing possible implementation issues |
nice idea. however, I think this might be better done in e.g.
normally not in favor of doing this (e.g. messing with an imported package namespace), but this seems that otherwise you would have to add keywords all over the place which makes the pandas API a bit odd. alternatively you can create a class
then provide methods to draw the blocks on that, and forward methods to the contained df both a bit non-trivial though |
@jreback Thanks.. I'll try to explore the idea a little more in the context I'm currently working in (putting together IPython notebooks for a distance learning context) to see what seems tractable/useful and what major cases fall out. |
Looks like this hasn't progressed in more than a year now. Is the unanimous view still to only accept a formatter architecture that fits all use cases? Or would a step change be acceptable? I think it would already be a huge improvement if the |
Great to hear this is nearing completion! Might be worth adding a reference to #10250 in the opening post for those digging through issues around output formatting (I don't have the required permissions). |
to_string()
,to_html()
,to_latex()
,formatters
,float_format
, etc.related #459
see Possible interactions with taldcroft/asciitable? #167, Float format syntax #2502, ENH: add escape parameter to to_html() #2919 (comment), Multilevel indexing with .to_latex() method merges two index columns #2942, Multilevel indexing with .to_latex() method merges two index columns #2924,HTMLFormatter.to_html() does not look at show_index_names #3195, Update DataFrame.to_latex() to have more flexibility #3196,ENH: update DataFrame to_latex for nicer typesetting #3264, BUG: adjust to_latex column format when no index #3467, Update DataFrame.to_latex() to have more flexibility #3197,ENH: Remove the hardcoded border=1 in the to_html dataframe export. #4578,API: Would it be useful for everyone if DataFrame.to_html (and to_string) had an argument to specify justify settings for each column? #4315, ml1., BUG: formatters argument to DataFrame.to_latex() is broken #6052
the output formats were added for convenience, but don't see much
ongoing work (formatting tables isn't sexy).
in a way that naturally extends pandas.
Template engines [jinja2, mako] are the accepted way of converting data into documents,
and the web dev community has provided great libraries to do it.
We should piggyback.
This would be good:
do it, or ignoring "fringe" use cases.
have their output blend into python, and they can contribute / manage / source-control
document templates in a clean, self-contained way.
olden 2.5 support days. No more parameter hell necessary to make the existing methods
more expressive. I never ever want to format html tables using function arguments.
python strings.
However,
So,
library and use it for rendeing
The text was updated successfully, but these errors were encountered: