How to embed data in an IPython Notebook?

jupyter-notebook, pandas, python

Solution

You could put this in an IPython cell:

import pandas as pd
import io
content = '''\
<<PASTE DATA HERE>>
'''

df = pd.read_table(io.BytesIO(content), ...)

Problem

Seems to me that there ought to be a way to read data from a file, ideally into a Pandas DataFrame and create the result in such a way that it becomes part of the notebook, so for instance you can store the data right in the notebook without needing external files? That way you can send entire examples (obviously mainly for smaller data sets). It would also make doing examples way easier here on SO.. Any Ideas? Even via cut and paste ie output of a dataframe display?

Original source