是否可以使用api将数据帧保存到atlassian页面?

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

如何使用Python中的API将pandas数据框直接保存到Atlassian Confluence页面? 我使用 atlassian-python-api 库。但没有得到任何解决方案。

python-3.x pandas dataframe confluence
2个回答
1
投票

如果您使用altassian python api,您应该能够相对轻松地做到这一点

confluence 模块的文档中,运行

confluence.create_page
命令将在给定的工作区中创建一个页面。

confluence.create_page(space, title, body, parent_id=None, type='page', representation='storage', editor='v2')

在您的情况下,如果您想将 pandas 数据框创建为 Confluence 中的表,则应该使用 pandas 版本 1.0.0 中引入的

DataFrmae.to_markdown
命令。

docs,该命令将生成 markdown,您可以在下面看到。

s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
print(s.to_markdown())


|    | animal   |
|---:|:---------|
|  0 | elk      |
|  1 | pig      |
|  2 | dog      |
|  3 | quetzal  |

这将产生降价。

动物
0 麋鹿
1
2
3 绿咬鹃

在您的情况下,您应该尝试将 markdown 分配给 body 参数

 confluence.create_page(space, title, body=df.to_markdown(), parent_id=None, type='page', representation='storage', editor='v2')

这应该会产生你想要的结果。


0
投票

@zhqiat提供的方法的另一种选择是将数据帧转换为html。

df = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")

confluence.create_page(
    space, 
    title, 
    body=df.to_html(), 
    parent_id=None, 
    type='page',
    representation='storage', 
    editor='v2',
)

在我的情况下

DataFrame.to_markdown()
不起作用,似乎换行符存在问题( )。但
DataFrame.to_html()
确实有效。

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