-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Custom column formatters for HTML in IPython, e.g. can show np 2D-array as image #9579
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
this would need to be implemented like:
so if a formatter exists for a particular column, or genreally then it would get called to generate the html. this would be then fairly generic. |
Yes, that makes sense, but you also need some way to attach the |
you cannot copy meta-data like this. It is in theory possible, but this introduces all kinds of issues. Much better to simply pass it to |
If it's a lot more complicated to do it as meta-data then I'll settle for what you are suggesting. In fact that would probably be ok for my usage case, as I'm using a DataFrame as the backend of a custom DataSet class, i.e. I can explicitly call Since you seem to have a pretty good idea of what you'd like to see here, and it doesn't seem that far off what is already suggested, can I ask you to finish it off? p.s. This is my first ever pull request to an open-source project, so I don't know what the etiquette is. |
@d1manson well, would love to have you contribute. why don't you change around a bit to use it in calling |
is that any better? |
looks closer. What would help this is a few tests for this kind of behavior. E.g. you assert that the generated html is correct. see |
Any progress on this? I think this is a VERY useful feature, that will make IPython notebook a lot more powerful as a data presentation tool - I see a LOT of use cases:
In my opinion, this should be quite a priority for pandas. |
@richlewis42 would love to have another contributor to this. There are several linked issues. This requires a bit of a comprehensive, though not too difficult feature set. |
I would love to contribute, although I am very new to open source, and to the internals of pandas. If there is anything specific that I could do to push this forward, please let me know. |
here what would help a code example which shows an api of what a user would do eg construct a sample frame programmatically this is not a difficult issue to fix but needs a reasonably rich api spec |
I will give this a try when I get back from work, hopefully over the weekend. Thanks for the ideas. |
if you guys want to update for 0.17.0 that would be gr8! |
Hi, sorry I've been off the case for ages, I've been really busy at work. I thought about what could be useful, and it seems to me that the simplest thing would be that if an object in a DataFrame offers an HTML representation (i.e. implements |
@richlewis42 that is a really nice idea, actually. For example, it would work well with geopandas, which holds shapely objects inside a column. These objects already have an |
I would vote for both: if a custom formatter is provided, then use that, otherwise if a The advantage of the custom formatter is that it gives you a lot of control:
Of course one approach would be to wrap each of the objects in the column in a custom object which handles the |
I agree, these are not necessarily mutually exclusive. Recursive support for |
Agreed, I still like the custom formatters, and think they would be very helpful. Could the recursive Or shall I open another pull request for recursive |
This PR needs a bit of extra work to go in -- notably it needs some tests and slightly better docs. I'll add comments inline in the code. @richlewis42 I haven't taken a look at the code carefully yet, so up to you on the best order to add this. This PR is also probably going to make it in shortly and might help a title bit (see the Edit: to clarify, I do think it's probably a good idea to add |
names will be given defaults or ignored respectively. If list/tuple | ||
the length should match the columns exactly. | ||
Each callable can have an optional boolean `escape` attribute, | ||
and an optional string `justify` attribute. See `_make_fixed_width` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please give a brief description instead of referring to the source code? Also -- maybe add an example to the HTML a export docs? http://pandas-docs.github.io/pandas-docs-travis/io.html#io-html
Mostly this just needs tests to verify the stated functionality. |
...rather than dataframe meta-data. Also tidied logic a little and added docstring.
I think this could be done as part of #10250 with just a formatter method(s) (as you have several functionailites added), so closing, but welcome extensions as part of that PR (or after) |
I've created a gist to explain in more detail, and with a screenshot.