Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Created November 22, 2016 22:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrocklin/ada85ef06d625947f7b34886fd2710f8 to your computer and use it in GitHub Desktop.
Save mrocklin/ada85ef06d625947f7b34886fd2710f8 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"http://dask.readthedocs.io/en/latest/_images/dask_horizontal.svg\"\n",
" align=\"right\"\n",
" width=\"30%\"\n",
" alt=\"Dask logo\">\n",
"\n",
"TimeSeries\n",
"=======================\n",
"\n",
"<img src=\"http://www.numfocus.org/uploads/6/0/6/9/60696727/6893890_orig.png\"\n",
" align=\"left\"\n",
" width=\"30%\"\n",
" alt=\"Pandas logo\">\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Connect to Cluster"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from dask.distributed import Client, progress\n",
"c = Client('127.0.0.1:8786')\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Read Data from S3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import dask.dataframe as dd\n",
"\n",
"df = dd.read_csv('s3://dask-data/nyc-taxi/2015/*.csv', \n",
" parse_dates=['tpep_pickup_datetime', 'tpep_dropoff_datetime'],\n",
" storage_options={'anon': True})\n",
"\n",
"df = c.persist(df)\n",
"progress(df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Re-index by Datetime Column (shuffle)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"df = c.persist(df.set_index('tpep_pickup_datetime'))\n",
"progress(df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Inspect result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df.tail()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df.loc['2015-05-05'].head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Resample by day"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"(df.passenger_count\n",
" .resample('1d')\n",
" .mean()\n",
" .compute()\n",
" .plot())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Group by day of week"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"(df.passenger_count\n",
" .groupby(df.index.dayofweek)\n",
" .mean()\n",
" .compute()\n",
" .plot())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment