Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting pandas dataframe to wiki markup table

I'm automating some data processing and creating jira tickets out of it. Pandas does have to_html or to_csv or even to_markdown. But jira supports only wiki markup for creating a table.

e.g.

<!-- wiki markup -->
||header1||header2||header3||\r\n|cell 11|cell 12|cell 13|\r\n|cell 21|cell 22|cell 23|

will create

header1 header2 header3
cell 11 cell 12 cell 13
cell 21 cell 22 cell 23

Is there anyway to convert pandas dataframe to wiki markup table to be used in Jira?

I'm keeping df.iterrows as Last resort since iterating over dataframe is not a recommended solution as per answers in How can I iterate over rows in a Pandas DataFrame? Since my expected dataframe is small, iteration should be fine in my case. This question can be considered as more of a curiosity what can be done in case of larger dataframes.

like image 542
RatDon Avatar asked Jan 22 '26 22:01

RatDon


1 Answers

Don't reinvent the wheel, tabulate supports a jira template:

from tabulate import tabulate

tabulate(df, headers='keys', tablefmt='jira', showindex=False)

Output:

'|| header1   || header2   || header3   ||\n| cell 11   | cell 12   | cell 13   |\n| cell 21   | cell 22   | cell 23   |'

If you really want the \r\n line separator:

tabulate(df, headers='keys', tablefmt='jira', showindex=False).replace('\n', '\r\n')
like image 53
mozway Avatar answered Jan 24 '26 14:01

mozway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!