動画 → https://twitter.com/urekat/status/1305719610956677120?s=20
.py
from IPython.display import HTML
def popup(df, windowName="default", width=1200, height=1350, top=30, left=-1):
css = """<style>
table { border-collapse: collapse; border: 3px solid #eee; }
table tr th:first-child { background-color: #eeeeee; color: #333; font-weight: bold }
table thead th { background-color: #eee; color: #000; }
tr, th, td { border: 1px solid #ccc; border-width: 1px 0 0 1px; border-collapse: collapse;
padding: 3px; font-family: monospace; font-size: 16px }</style>
"""
top_js = f"screen.height {top}-{height}" if top<0 else f"{top}"
left_js = f"screen.width {left}-{width}" if left<0 else f"{left}"
s = '<script type="text/javascript">\n'
s += '(function(){\n'
s += ' if(!window._windows) window._windows = {};\n'
s += ' var win = window._windows["'+windowName+'"]; if(win && win.closed) win = null;\n'
s += ' if(!win) win = window._windows["'+windowName+'"] = window.open("", "'+windowName+'", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width='+str(width)+', height='+str(height)+', top=\"+('+top_js+')+\", left=\"+('+left_js+'));\n' #......
s += ' win.document.body.innerHTML = \'' + (df.to_html() + css).replace("\n",'\\n') + '\';\n\n'
s += ' win.document.body.style.backgroundColor = "#ffffcc";\n'
s += ' setTimeout(function(){ win.document.body.style.backgroundColor = \'#ffffff\'; }, 500);\n'
s += ' win.onfocus = function(){ win.document.body.style.backgroundColor = \'#ffffff\'; };\n'
s += ' win.onblur = function(){ win.document.body.style.backgroundColor = \'#fcfcfc\'; };\n'
s += '})();\n'
s += '</script>'
return(HTML(s+css))
.py
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randn(300,4),columns=list('ABCD'))
popup(df1, windowName="a", width=1200, height=600, top=30, left=-1)
.py
df2 = pd.DataFrame(np.random.randn(300,7),columns=list('ABCDEFG'))
popup(df2, windowName="b", width=1200, height=600, top=700, left=-1)
参考: https://stackoverflow.com/questions/40554839/pop-out-expand-jupyter-cell-to-new-browser-window