Skip to main content

Citibike-Sampler

A Python tool to facilitate work with data from NYC's Citi Bike network.


Why use this?

Data from the 'Citi Bike' system in NYC captures real-world patterns of urban mobility at very high resolution. As such, the data is widely used in research and practical applications.

However, working with the raw source data can be tedious. In a single year, the Citi Bike system records tens of millions of bike rides, equating to several GB worth of data. Furthermore, historical trip records are spread over hundreds of CSV files that use an inconsistent archive layout over time (annual bundles before 2024, monthly archives after).

Citibike-Sampler streamlines your workflow by providing:

  • a convenient data downloader with consistent local caching;
  • a data loader for accessing the full trip records; and
  • a random sampler to draw representative subsets of the full Citi Bike data spanning multiple months or years.

Random sampling allows you to quickly explore multi-year trends in the Citi Bike data, without having to load hundreds of millions of records into memory.


Installation

pip

Citibike-Sampler is available on PyPI and can be installed using pip:

pip install citibike-sampler

pipx (for CLI use)

If you only need data sampling from the command-line, installation is best done using pipx:

pipx install git+https://github.com/lungoruscello/Citibike-Sampler.git

Usage

Python API

from citibike_sampler import sample, load_all, get_cache_dir

# Randomly sample 1% of all trip records from the first half of 2025.
# (Will automatically download data from AWS if not already cached.)
sample_df = sample(start='2025-1', end='2025-6', fraction=0.01, seed=42)

# Plot daily aggregates of sampled trips (assumes matplotlib is available)
sample_df.set_index('ended_at').resample('1D').ride_id.count().plot()

# Load the full dataset (be careful: millions of rides per month!)
full_df = load_all(start='2025-1', end='2025-6') 

print(len(sample_df) / len(full_df))  # check the sampling fraction

print(get_cache_dir())  # inspect the local cache location  

CLI

Generate a random sample of Citi Bike data directly from the terminal:

cbike_sampler --start 2025-1 --end 2025-6 --fraction 0.01 --seed 42 --output sampled.csv

This will create a sampled.csv file containing roughly 1% of all trip records from the first half of 2025. To store the sampling result as a Feather or Parquet file, simply change the suffix of the output filename accordingly (e.g., sampled.parquet).

Requirements

  • Python 3.9 or higher
  • requests
  • pandas
  • tqdm
  • pyarrow (optional, for Parquet/Feather export)

Licence

MIT Licence. See LICENSE.txt for details.

Metadata

Release files for citibike-sampler 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citibike-sampler 0.1.0
File Size Uploaded
citibike_sampler-0.1.0.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for citibike-sampler 0.1.0
File Interpreter ABI Platform
citibike_sampler-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.1 kB

Release files / citibike_sampler-0.1.0.tar.gz

Download URL citibike_sampler-0.1.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
052c7c86750a5fd5eca37063cf0bd914ebed404b168d6f3d9702a686a75ec762
BLAKE2b-256 checksum
How to use checksums
fc2bef1e90327f8e998ad1b127d10c93a6e1813b7733454c368c7f67cde08160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / citibike_sampler-0.1.0-py3-none-any.whl

Download URL citibike_sampler-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea2acc39ebc4aa81f4468ab0a7511854f6bd9533a8a96eee3c00bd080dc9902e
BLAKE2b-256 checksum
How to use checksums
d70d81f3cfba7a9009c44b351c7f3cfce4991c327d56e8305f430b7c15cf5c5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page