iPython - 在新标签中显示完整的数据框 [英] iPython - Display full dataframe in new tab
问题描述
当我想控制数据帧时,我通常将其导出为.csv,然后在Excel中打开。
我正在寻找更快的方法,但我不愿意将全帧显示在我的笔记本中,因为它使其无法读取。
由于帧的正常输出是一个HTML表格,我想知道我们如何能够在除笔记本之外的其他地方显示该表格。
您可以将 javascript
与一起使用ipython.display
打开一个新窗口并在其中显示整个数据框。优点是您可以多次执行此操作,而无需在其间创建实际的HTML文件或重新加载窗口。自动我的问题解决方案更新打开的窗口,并从 R / RStudio
模拟 View()
函数:
$ b
导入HTML
def查看(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(,标题,toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = y es,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 + = '< / script>'
返回(HTML(s + css))
查看(df)
in Jupyter, using Pandas, is there a way to show an entire dataframe in a new tab of the navigator?
When I want to control a dataframe, I usually export it in .csv and then open in Excel.
I am looking for a faster way, but I am not willing to display the full frame into my Notebook, as it make it unreadable.
Since the normal output of a frame is an HTML table, I wonder how we can show this table elsewhere than in the Notebook.
You could use javascript
together with ipython.display
to open a new window and show the whole dataframe in it. The advantage is that you can do that several times without the need to create actual HTML files in between or to reload the window. My solution for that question automatically updates the opened window and kind of emulates the View()
function from R/RStudio
:
from IPython.display import HTML
def View(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 += '</script>'
return(HTML(s+css))
View(df)
这篇关于iPython - 在新标签中显示完整的数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!