diff --git a/nbs/index.ipynb b/nbs/index.ipynb index 5266a21..c7fb84b 100644 --- a/nbs/index.ipynb +++ b/nbs/index.ipynb @@ -988,8 +988,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Manipulating data\n", - "\n", + "## Manipulating data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "We try to make the following methods as flexible as possible. Wherever possible, they support Python dictionaries, dataclasses, and classes. " ] }, @@ -1183,6 +1188,49 @@ "cats.delete(cat.id)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Importing CSV/TSV/etc" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can pass a file name, string, bytes, or open file handle to `import_file` to import a CSV:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'id': 1, 'name': 'Alice', 'age': 30},\n", + " {'id': 2, 'name': 'Bob', 'age': 25},\n", + " {'id': 3, 'name': 'Charlie', 'age': 35}]" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db = Database(\":memory:\")\n", + "csv_data = \"\"\"id,name,age\n", + "1,Alice,30\n", + "2,Bob,25\n", + "3,Charlie,35\"\"\"\n", + "\n", + "table = db.import_file(\"people\", csv_data)\n", + "table()" + ] + }, { "cell_type": "markdown", "metadata": {},