带有熊猫多表的新窗口中的ipython小部件

时间:2018-06-25 12:44:50

标签: pandas ipython jupyter-notebook

使用在堆栈交换中找到的以下代码,我弄清楚了如何获取一个单元格的输出(两个pandas dataFrames)以打开到新的浏览器窗口中,其格式使得两个dataFrames并排显示-面:

#### for displaying tables side-by-side
def multiTable(table_list): 
    ''' Acceps a list of IpyTable objects and returns a table which contains each IpyTable in a cell
    '''
    return HTML(
    '<table><tr style="background-color:white;">' + 
    ''.join(['<td valign="top">' + table._repr_html_() + '</td>' for table in table_list]) +
    '</tr></table>'
)
def newWindow(df):
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: 10px }</style>
"""
s  = '<script type="text/Javascript">'
s += 'var win = window.open("", "Title", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));'
s += 'win.document.body.innerHTML = \'' + (df.to_html() + css).replace("\n",'\\') + '\';'
#s += 'win.document.body.innerHTML = \'' + (df).replace("\n",'\\') + '\';'
s += '</script>'

return(HTML(s+css))

我想要做的是使用widget()具有相同的布局(新窗口,并排df显示)。但是,以下方法不能很好地发挥作用:

widget = widgets.Output()
with widget:
     display(multiTable)[df1,df2])

用例是比较两个数据帧,并使用循环按顺序向这些df输入更改,以在每次更改后使用更改来更新并重新显示具有更改的表。 widget()调用可以从视觉上清除它。但是,将输入放在单独的窗口中会带来更好的用户体验。

这是我第一次做接近图形编程的事情,所以请让我知道我是否真的树错了树。

0 个答案:

没有答案
相关问题