-
-
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
DataFrame rendering stylists? #459
Comments
Interesting idea. How about instead of the argument being a nested dictionary make it a function of two arguments? Your code would become:
I renamed the argument to be singular since it accepts just one function. This would also allow you to compose multiple styling functions by wrapping them, or have styling that's algorithmic instead of defined statically in a data-structure. Sure you could achieve the same thing using your approach and defining getitem on a class, but that's just more busywork. |
Hi all, Here is a very simple example of how the final result would look like: <html>
<head>
<script>
function toggle(thisname) {
tr=document.getElementsByTagName('tr')
for (i=0;i<tr.length;i++){
if (tr[i].getAttribute(thisname)){
if ( tr[i].style.display=='none' ){
tr[i].style.display = '';
}
else {
tr[i].style.display = 'none';
}
}
}
}
</script>
</head>
<body>
<table border=1>
<tr onClick="toggle('hide1');"><td >Main Row 1</td><td >Value 1</td></tr>
<tr hide1=yes ><td>Subrow 11</td><td >Value 11</td></tr>
<tr onClick="toggle('hide2');"><td>Main Row 2</td><td >Value 2</td></tr>
<tr hide2=yes ><td>Subrow 21</td><td >Value 21</td></tr>
<tr hide2=yes ><td>Subrow 22</td><td >Value 22</td></tr>
<tr onClick="toggle('hide3');"><td>Main Row 3</td><td >Value 3</td></tr>
<tr hide3=yes ><td>Subrow 31</td><td >Value 31</td></tr>
<tr hide3=yes ><td>Subrow 32</td><td >Value 32</td></tr>
<tr onClick="toggle('hide4');"><td>Main Row 4</td><td >Value 4</td></tr>
<tr hide4=yes ><td>Subrow 41</td><td >Value 41</td></tr>
<tr hide4=yes ><td>Subrow 42</td><td >Value 42</td></tr>
</table>
</body>
</html> So basically the to_html code would need:
What do you think? |
closing in favor of #3190 |
The approach below appears to work great for calculating the correct column print width when ANSI codes are involved. You can replace the "TextAdjustment" class with the version below in this file:
|
FYI, pandas.compat is considered private:
https://pandas.pydata.org/pandas-docs/stable/reference/index.html
…On Fri, Oct 18, 2019 at 9:59 AM Celyn Walters ***@***.***> wrote:
Thanks @ghost711 <https://github.com/ghost711>!
For posterity, compat.strlen seems to have been removed in #25903
<#25903>.
I added it back in to this file with (simply):
def strlen(data, encoding=None):
return len(data)
and also needed:
import pandas.compat as compat
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#459?email_source=notifications&email_token=AAKAOIUBL5ISIDLJEGNKT4DQPHFOXA5CNFSM4AMJVTN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBUYGKI#issuecomment-543785769>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAOIRYAVQAC4FDUOM7K7DQPHFOXANCNFSM4AMJVTNQ>
.
|
Been working a bit on the idea of DataFrame rendering stylists. Would like some feedback on the idea / API.
Idea is that on top of the formatters used in
DataFrame.to_string()
andDataFrame.to_html()
, i would like to add stylists. A stylist takes as input a string and returns a string, allowing to alter the string representation of each individual cell of a DataFrame. Each DataFrame element goes first through a formatter and the string result from this goes through a stylist. This allows to use e.g ANSI escape sequences to change text, background color of how a DataFrame cell is displayed on screen. Or in theDataFrame.to_html()
case, a stylists can add html div, class tags - which combined with css change the rendering of a html table cell.This is the description of stylists and new API for
DataFrame.to_string()
andDataFrame.to_html
A little demo when using stylists on screen:
Results in the following (there should be an image here below):
As you can see, more work is needed. The ANSI escape sequences are taken into account when determining the number of characters needed for each column, this is not needed since they are invisible. Solution is e.g to set column widths before stylists are applied, implying that a stylist can not change the width of a column - seems reasonable.
Or maybe this should be taken one step further and find some way to combine the functionality of both formatters and stylists into one (have not thought about how this should look)? Ideas, feedback?
The text was updated successfully, but these errors were encountered: