Simple Markdown Table Output From pandas DataFrames

In passing, I note that we can easily generate simple markdown style table output from a pandas data frame using the pandas .to_markdown() dataframe method:

Here’s the associated code fragment:

data = """colA, colB, colC
this, that, 1
or, another, 2"""

import pandas as pd
from io import StringIO

df = pd.read_csv(StringIO(data))
md_table = df.to_markdown(index=False)


I also note that Stack Overflow recently (ish!) added support for markdown tables (announcement) using Github-flavoured markdown syntax.

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: