2016-11-04 101 views
1

我想在Pandas 0.19中使用newly included 'style'格式化我的數據框。我試圖使用完全相同的腳本複製相同的東西,但我得到一個Styler對象。如何使用熊貓DataFrame.style?

>>> df 
       Security  Price Change Percentage ChgNetValue LastClose 
10  Japan Five-Year -0.207000   -4.020000 -0.008000 -0.199000 
13  U.S. 10-Year 97.406250  5274.434452 95.593850 1.812500 
20  U.S. 30-Year 93.156250  3481.253980 90.555031 2.601562 
23  U.S. 3M T-Bill 0.355000   -2.068966 -0.007500 0.362500 
31  U.S. Five-Year 100.015625  7803.952347 98.750237 1.265625 
36 Eurozone Five-Year -0.423000   -3.171000 -0.013000 -0.410000 
43  U.S. Two-Year 99.898438  12271.036276 99.090919 25.875000 
44  U.K. Five-Year 0.529000   -3.114000 -0.017000 0.546000  
>>> df.style 
    <pandas.formats.style.Styler object at 0x0000000008133F28> 
>>> s = df.style.applymap(color_negative_red) 
>>> s 
    <pandas.formats.style.Styler object at 0x00000000035116A0> 

我具有完全相同的功能,color_negative_red,如在文檔中。我在Eclipse中這樣做,而不是IPython。

我想是使用to_html()和應用條件格式在數據幀的每個號碼。有一個更好的方法嗎?

回答

2

見下Out [2]here的說明。 Styler對象定義了一個在筆記本中呈現HTML的_repr_html_

獲得實際的HTML字符串,你叫styler.render()