This is a very helpful and neat solution. However, I can't get this to work with tables. I intend to take data frames and output a mark down report containing text and tables.
To do this my plan was to convert the spark DataFrame to a pandas DataFrame and then use the pandas to_markdown function to create table text and then use the above solution to output this into a Databricks cell. I.e.
md_table = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal").to_markdown()
markdown = f'''{md_table}'''
Markdown(markdown)
However, this doesn't work and I get this output from the cell:
| | animal | |---:|:---------| | 0 | elk | | 1 | pig | | 2 | dog | | 3 | quetzal |
As you can see the output doesn't have carriage returns between the lines but adding them to the string doesn't work either.
Has anyone successfully rendered a pandas (or spark) DataFrame to markdown?