{% extends "base.html" %} {% block title %}Export {{ count }} rows to a notebook{% endblock %} {% block extra_head %} {% endblock %} {% block content %}

Export {{ count }} rows to a notebook

Back to the rows

You can export this data to a Jupyter or Observable notebook by copying and pasting the following:

Jupyter

Make sure you have Pandas. Import it in a cell like this:

import pandas
If this shows an error you can run %pip install pandas in a notebook cell to install it.

Now paste the following into a cell to load the {{ count }} row{% if count != 1 %}s{% endif %} into a DataFrame called df:

df = pandas.read_json({{ json.dumps(json_url) }})

Run df in a new cell to see the table.

{% if allow_csv_stream and csv_stream_url and total_count and total_count > count %}

You can export all {{ "{:,}".format(total_count) }} rows using a single streaming CSV export like this:

{{ pandas_stream_code }}
{% endif %}

Observable

{% if cors_enabled %}

Import d3 by running this in a cell:

d3 = require("d3@5")

Now import the data into a variable called rows like this:

rows = d3.json({{ json.dumps(json_url) }})
{% if allow_csv_stream and csv_stream_url and total_count and total_count > count %}

You can export all {{ "{:,}".format(total_count) }} rows using a single streaming CSV export like this:

rows = d3.csv({{ json.dumps(csv_stream_url) }})

This could lose type information, since every column in a CSV import will be treated as text.

{% endif %} {% else %}

Export to Observable is only available if Datasette is running with the --cors option.

{% endif %} {% endblock %}