Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Created January 27, 2021 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrocklin/05605ae8c3f673039abdd4212cb3301c to your computer and use it in GitHub Desktop.
Save mrocklin/05605ae8c3f673039abdd4212cb3301c to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "urban-lambda",
"metadata": {},
"source": [
"## Streamz"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "sound-booth",
"metadata": {},
"outputs": [],
"source": [
"import streamz\n",
"\n",
"source = streamz.Source()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "green-memorial",
"metadata": {},
"outputs": [],
"source": [
"def inc(x):\n",
" return x + 1\n",
"\n",
"def double(x):\n",
" return 2 * x"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "signed-force",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8d889350f36a4df0b2b15ce27753e31c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"a = source.map(inc)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "secondary-temple",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eceb19632b1b477cbce9dcccbd5c3354",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"b = source.map(double)\n",
"b"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "comprehensive-coral",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"id": "third-channels",
"metadata": {},
"outputs": [],
"source": [
"source.emit(10)"
]
},
{
"cell_type": "markdown",
"id": "incorrect-triple",
"metadata": {},
"source": [
"## Streaming dataframes"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "organized-contribution",
"metadata": {},
"outputs": [],
"source": [
"import streamz\n",
"import streamz.dataframe"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "certified-voluntary",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "47d0a3d1dbe04c74aff9efb43f3be825",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df = streamz.dataframe.Random()\n",
"df.tail()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "aquatic-capture",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8bf8ddd6ad304bbca7910367c0ea4830",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.x.sum()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "royal-penalty",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "004df47cefb04c949176dda0788c463a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.groupby(\"y\")[[\"x\", \"y\"]].mean()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "packed-director",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4998123614ae40db8691f39937c5103e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.stream.map(type)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "young-mobile",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment