Last active
January 22, 2020 10:01
-
-
Save finete/513142c983e16227b0a0f0d55529bc54 to your computer and use it in GitHub Desktop.
display several objects (including pandas data frames) side by on jupyter lab/notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class display: | |
"""Display HTML representation of multiple objects""" | |
template = """<div style="float: left; padding: 10px;"> | |
<p style='font-family:"Courier New", Courier, monospace'>{0}</p>{1} | |
</div>""" | |
def __init__(self, *args, **kwargs): | |
self.args = args | |
self.kwargs = kwargs | |
def _repr_html_(self): | |
lst_temps = [] | |
for name, val in self.kwargs.items(): | |
lst_temps.append(self.template.format(name, self._safe_repl(val))) | |
kwargs_str = '\n'.join(lst_temps) | |
return kwargs_str+'\n'.join(self.template.format(a, self._eval(a)) | |
for a in self.args) | |
def _eval(self, val): | |
return self._safe_repl(eval(val)) | |
def _safe_repl(self, val): | |
try: | |
return val._repr_html_() | |
except AttributeError: | |
return val.__repr__() | |
def __repr__(self): | |
return '\n\n'.join(a + '\n' + repr(eval(a)) | |
for a in self.args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment