How to save pandas dataframe directly to Atlassian confluence page using API in python? I used atlassian-python-api library. but didn't get any solution.
How to save pandas dataframe directly to Atlassian confluence page using API in python? I used atlassian-python-api library. but didn't get any solution.
In the future, please review how to ask questions that are MCVE so that others can help you more easily.
If you are using the altassian python api, you should be able to do this relatively easily
from the documentation for the confluence module, running the confluence.create_page command will create a page in your given workspace.
confluence.create_page(space, title, body, parent_id=None, type='page', representation='storage', editor='v2')
In your case, if you want to create the pandas dataframe as a table in confluence, you should use the DataFrmae.to_markdown command introduced in pandas version 1.0.0.
From the docs, the command will generate markdown which you can see below.
s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal")
print(s.to_markdown())
| | animal |
|---:|:---------|
| 0 | elk |
| 1 | pig |
| 2 | dog |
| 3 | quetzal |
Which will yield markdown as such.
| animal | |
|---|---|
| 0 | elk |
| 1 | pig |
| 2 | dog |
| 3 | quetzal |
In your case, you should attempt to assign the markdown to the body parameter
confluence.create_page(space, title, body=df.to_markdown(), parent_id=None, type='page', representation='storage', editor='v2')
Which should yield the result you desire.
Another option as the method provided by @zhqiat would be to convert the dataframe to 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',
)
In my case DataFrame.to_markdown() did not work, it seems that there were issues with the newline characters (\n). But DataFrame.to_html() did work.