GitHub不反映pandas样式

huangapple go评论61阅读模式
英文:

GitHub doesn't reflect pandas styles

问题

GitHub无法反映我使用pandas方法style()应用于数据框的样式。

datapivothappiness_score[datapivothappiness_score.index.isin(short_list)].style\
    .background_gradient(cmap='Greens')\
    .format(precision=1, thousands=".", decimal=",")

在VSCode上运行正常。

但在GitHub上不起作用。

英文:

GitHub does not reflect the styles that I applied to the dataframe using the pandas method style().

    datapivothappiness_score[datapivothappiness_score.index.isin (short_list)].style\
    .background_gradient(cmap='Greens')\
    .format(precision=1, thousands=".", decimal=",")

At VSCode it warks good
GitHub不反映pandas样式
But not at GitHib
GitHub不反映pandas样式

答案1

得分: 1

可能是因为GitHub以静态HTML形式呈现代码,而不是交互式笔记本,所以无法正确显示样式。如果您想查看带有应用样式的数据框,可以尝试将笔记本转换为其他格式,如HTML或PDF。

另外,您可以尝试使用to_html方法将样式化的数据框转换为HTML,然后在GitHub上显示HTML。以下是如何执行此操作的示例:

styled_df = datapivothappiness_score[datapivothappiness_score.index.isin (short_list)].style\
    .background_gradient(cmap='Greens')\
    .format(precision=1, thousands=".", decimal=",")

html = styled_df.render()

# 将HTML保存到文件
with open('styled_dataframe.html', 'w') as f:
    f.write(html)

# 在GitHub上显示HTML(必须放在反引号内)
print(f'`{html}`')

然后,将反引号内的HTML输出复制并粘贴到GitHub README文件中的Markdown单元格中,它应该能够正确显示。

请注意,此方法只会将样式化的数据框显示为静态HTML表格,不具有任何交互式功能。

英文:

It's possible that GitHub is not displaying the styles properly due to the fact that it's a static HTML rendering of your code and not an interactive notebook that can fully display the styles. You can try converting your notebook to another format such as HTML or PDF if you want to view your dataframe with the applied styles.

Alternatively, you can try using the to_html method to convert your styled dataframe to HTML and then display the HTML on GitHub. Here is an example of how to do this:

styled_df = datapivothappiness_score[datapivothappiness_score.index.isin (short_list)].style\
    .background_gradient(cmap='Greens')\
    .format(precision=1, thousands=".", decimal=",")
    
html = styled_df.render()

# Save the HTML to a file
with open('styled_dataframe.html', 'w') as f:
    f.write(html)

# Display the HTML on GitHub (must be placed within backticks)
print(f'`{html}`')

Then, copy and paste the HTML output within the backticks into a Markdown cell in your GitHub README file, and it should display properly.

Note that this method will only display the styled dataframe as a static HTML table and will not have any interactive features.

huangapple
  • 本文由 发表于 2023年6月19日 21:13:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定