Markdown Toolbox Logo Markdown Toolbox
Home
Blog

Converting DataFrames to Markdown

2024-09-07

Short version

To convert a DataFrame to Markdown, you can use Pandas:

import pandas as pd

df = pd.DataFrame({
    'Column1': [1, 2],
    'Column2': [3, 4]
})

print(df.to_markdown())

Long version

Introduction

Converting DataFrames from libraries like Pandas to Markdown is a great way to create tables for documentation or reports.

Example Code

  • Ensure you have Pandas installed by running pip install pandas.

  • Create a DataFrame and then convert it:

    import pandas as pd
    
    df = pd.DataFrame({
        'Column1': [1, 2],
        'Column2': [3, 4]
    })
    
    print(df.to_markdown())
    

Conclusion

Using Pandas to convert DataFrames into Markdown tables streamlines the process of sharing data in a readable format.