2017-05-31 60 views
1

當我使用風格來格式化Jupyter筆記本中的熊貓數據框時,不會顯示列的名稱(df.columns.name)。 我該如何解決這個問題?熊貓風格不顯示列名

設置:

import pandas as pd 
from IPython.display import HTML, display 

df = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]], columns = [-1,0,1], index=[-1,0,1]) 
df.index.name = 'A' 
df.columns.name = 'B' 

這是數據看起來怎麼樣:

display(df) # Has name of columns 'B' 

enter image description here

現在,我想要個格式添加到所有列:

display(df.style.format("{:.1%}"))  

enter image description here

但我失去了列的名字!

+0

我上面運行完全一樣的代碼,但是在第二個數據框的百分比中,上面的框中仍然有一個B列標籤。這可能是您的Jupyter版本中的一個錯誤。 – cardamom

回答

1

我試試你的代碼,而不是找你的問題,我得到這個: enter image description here

我想你更新你的熊貓或jupyter版本將解決這個問題。

+0

謝謝,我將筆記本更新至5.0,並且我有預期的行爲。 – FLab