2016-11-11 13 views
6

için jupyter hücresini genişletmek:/pop herhangi bir yolu var mıPop-out/Şöyle bir jupyter dizüstü hücreyi sahip yeni bir pencerede

enter image description here

(yeni bir tarayıcı penceresine bunu genişletmek çıktı satır içi değil)?

Temel olarak, R/RStudio ... 'dan View() işlevini çoğaltmak istiyorum ... Bu mümkün mü?

+1

Sen http://stackoverflow.com/questions/39977117/ipython-display-full-dataframe-in-new-tab ve http://stackoverflow.com/ gibi zamansal html dosyalarını kullanmayı deneyebilirsiniz sorular/37439014/olası-panda-veri-için-yeni-pencere-render-in-a-yeni pencere Veya başka bir pencerede verileri göster: Excel, PyQt veya tkinter http://stackoverflow.com/questions/10636024/python-pandas-gui-görüntüleme-a-dataframe-or-matrix –

cevap

12

HTML tarafından IPython.display aracılığıyla yürütülen yeni bir pencere açmak için Javascript'i kullanabilirsiniz. İşte

import pandas as pd 
import numpy as np 
df = pd.DataFrame(np.random.randn(6,4),columns=list('ABCD')) 
# Show in Jupyter 
df 

from IPython.display import HTML 
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().replace("\n",'\\') + '\';' 
s += '</script>' 

# Show in new Window 
HTML(s) 

, df.to_HTML() satırbaşıyla bolca içerir veri çerçevesinden bir HTML dizesini oluşturur. Bunlar Javascript için sorunlu. Javascript'teki çok satırlı dizeler, EOL'de ters eğik çizgi gerektirir; bu nedenle python, HTML dizesini .replace() yöntemiyle değiştirmelidir. Bu da masada anında etki yaratacaktır

df /= 2 
s = '<script type="text/Javascript">' 
s += 'win.document.body.innerHTML = \'' + df.to_html().replace("\n",'\\') + '\';' 
s += '</script>' 
HTML(s) 

: gerçekten serin Ne

JavaScript en .innerHTML (yerine document.write() ait) Yeni bir pencere oluşturmak için gerek kalmadan masayı her zaman güncelleyebilirsiniz olmasıdır açılan pencere basitçe yazarak

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)) 
Bu jupyter çalışır

: Burada enter image description here

python için R bir View() emülatörü basit öneri süslü tepesi olarak

View(df) 

, Ayrıca bazı CSS kullanarak açılan tablonuzu stilleri, çok daha güzel ve c RStudio'dan bildiğiniz kadarıyla kıyaslanamaz.
enter image description here

+0

. Bunu uygulamak isteyen herkes için bir ipucu: localhost'ta pop-up'ları engellemediğinizden emin olun! – emehex

İlgili konular