<jupyter_start><jupyter_text>NYC Taxi data  Import cuxfilter<jupyter_code>import cuxfilter
from bokeh import palettes
from cuxfilter.layouts import double_feature

import cudf
#update data_dir if you have downloaded datasets elsewhere
DATA_DIR = './data'<jupyter_output><empty_output><jupyter_text>Download required datasets<jupyter_code>! curl https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2015-01.csv --create-dirs -o $DATA_DIR/nyc_taxi.csv
from cuxfilter.sampledata import datasets_check
datasets_check('nyc_taxi', base_dir=DATA_DIR)<jupyter_output><empty_output><jupyter_text>preprocess the data<jupyter_code>cudf_df = cudf.read_csv(DATA_DIR + '/nyc_taxi.csv')

from pyproj import Proj, transform

inProj = Proj(init='epsg:4326') # Latitude and longitudes
outProj = Proj(init='epsg:3857') # 2D projected points

cudf_df['dropoff_x'], cudf_df['dropoff_y'] = transform(inProj, outProj, cudf_df['dropoff_longitude'].to_array(), cudf_df['dropoff_latitude'].to_array()) # Apply transformation

cudf_df = cudf_df.drop(['dropoff_latitude', 'dropoff_longitude'], axis=1)
cudf_df = cudf_df.dropna(axis=0)


cudf_df = cudf_df[(cudf_df.dropoff_x > -8239910.23) & (cudf_df.dropoff_x < -8229529.24) & (cudf_df.dropoff_y > 4968481.34) & (cudf_df.dropoff_y < 4983152.92)] # Filter over Manhattan


cudf_df.head()<jupyter_output><empty_output><jupyter_text>Read the dataset<jupyter_code>cux_df = cuxfilter.DataFrame.from_dataframe(cudf_df)<jupyter_output><empty_output><jupyter_text>Define charts<jupyter_code>from bokeh.tile_providers import get_provider as gp
tile_provider = gp('CARTODBPOSITRON')<jupyter_output><empty_output><jupyter_text>> Uncomment the below lines and replace MAPBOX_TOKEN with mapbox token string if you want to use mapbox map-tiles. Can be created for free here -https://www.mapbox.com/help/define-access-token/<jupyter_code>#from cuxfilter.assets.custom_tiles import get_provider, Vendors
#tile_provider = get_provider(Vendors.MAPBOX_LIGHT, access_token=MAPBOX_TOKEN)
chart1 = cuxfilter.charts.datashader.scatter_geo(x='dropoff_x',
                                         y='dropoff_y',
                                         aggregate_fn='count',
                                         tile_provider=tile_provider, x_range=(-8239910.23,-8229529.24), y_range=(4968481.34,4983152.92))

chart2 = cuxfilter.charts.bokeh.bar('passenger_count', data_points=9)<jupyter_output><empty_output><jupyter_text>Create a dashboard object<jupyter_code>d = cux_df.dashboard([chart1, chart2], layout=double_feature, theme=cuxfilter.themes.dark, title= 'NYC TAXI DATASET')
#dashboard object
d<jupyter_output><empty_output><jupyter_text>Starting the dashboard 1. d.show('current_notebook_url:current_notebook_port') remote dashboard2. d.app('current_notebook_url:current_notebook_port') inline in notebook (layout is ignored, and charts are displayed one below another)Incase you need to stop the server:- d.stop()<jupyter_code># d.show(notebook_url='')<jupyter_output><empty_output><jupyter_text>Export the queried data into a dataframe<jupyter_code>queried_df = d.export()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup