set_table_styles 不在 VSCode 中显示

问题描述 投票:0回答:2

蟒蛇 3.9.5

熊猫 1.2.4

我正在尝试学习如何对我的大熊猫使用样式并专门应用边框。但是,在使用 set_table_styles 时,我似乎无法正确反映我的显示。甚至直接复制另一个网站。

https://www.geeksforgeeks.org/display-the-pandas-dataframe-in-table-style-and-border-around-the-table-and-not-around-the-rows/

使用此代码:

df = pd.DataFrame({"A":[14, 4, 5, 4, 1], 
                "B":[5, 2, 54, 3, 2],  
                "C":[20, 20, 7, 3, 8], 
                "D":[14, 3, 6, 2, 6]})


# making a green border
df.style.set_table_styles([{'selector' : '','props' : [('border','2px solid green')]}])

只是给我没有任何边框的标准熊猫输出。 ` 当我使用:

df.render()

那里没有提到绿色边框。我需要做什么才能保存样式?

提前谢谢你!

python pandas visual-studio-code styling
2个回答
1
投票

也许你可以试试这个:

# making a yellow border
html=df.style.set_table_styles(
    [{"selector": "", "props": [("border", "10px solid yellow")]}]
).render()
  
# write html to file
text_file = open("index.html", "w")
text_file.write(html)
text_file.close()

然后打开Html文件。


0
投票

VS Code 渲染器无法正确显示边框。我花了一天时间试图了解为什么不显示边框,然后在 Jupyter Lab 中打开同一个文件,发现确实显示了边框。令人沮丧。我的用例想要像 Bloomberg 那样格式化数据,所以这将迫使我使用 Jupyter Labs,而 VS Code 几乎在所有其他方面都更容易。

© www.soinside.com 2019 - 2024. All rights reserved.