Skip to main content

Weighted aggregations along the local street network

Project description

pandana2

An example aggregating home values in Oakland. This is a screenshot - click here and scroll to the bottom for an interative map.

Screenshot 2025-04-11 at 4 48 27 PM

Motivating use case

The motivating use case of this library is to perform a mean of home prices (or anything else) in cities using local street networks. This solves two problems:

  1. We use network distance instead of "crows flies" distance because home prices on opposite sides of a freeway, for instance, are not as related as homes on a locally connected street network.
  2. Using smoothly overlapping distances along the street network reduces discontinuities that occur when observations are aggregated into polygons.

In short, the goal of this library is to compute weighted aggregations of all the observations within a certain network distance (e.g. 1500 meters or so) from every origin street intersection along the local street network. Weighted averages are easily computed so that observations closer to the origin node can be weighted higher.

Relationship to 2015 pandana

The original pandana was written during my graduate research with Paul Waddell at UC Berkeley. It leverages a huge C++ library for Contraction Hierachies which I eventually realized was useful to the routing queries but not useful to the aggregation queries. 10 years later, I finally got around to rewriting the library to not use C++ and only do the aggregations.

The "get nodes within X meters of each origin node in the network" part is written in numba. The rest is vanilla pandas. This should greatly ease extension and maintenance of the library since it's less than 1000 lines of code so far and much easier to deploy since it doesn't have to be compiled.

This version has feature parity with the 2015 version for the aggregations: it supports sum, mean, median, standard deviation, min, and max with no decay, linear decay and exponential decay. This version has weighted mean, weighted median, and weighted standard deviation which the previous version did not have. Additional aggregations and decays should be quite easy to add.

Example Notebook

The example Notebook is the best place to start to use this library. View the very short example Notebook here. Note the interactive map at the bottom of the notebook.

Documentation

There's just not a ton of documentation requred. Follow the example to see how to get a network and how to map data to the network. Otherwise, the only method that matters is:

def aggregate(
  values: pd.Series,
  decay_func: PandanaDecayFunction,
  aggregation: Aggregation | dict[str, Aggregation],
) -> pd.Series | pd.DataFrame:

values is a series where the index is node_ids from the nodes of the network and the values are floating point values you want to aggregate. In other words, it's the values and the node_ids they are located at (use the nearest_nodes method to assign node ids). node_ids can and likely will be repeated in the index (i.e. not unique).

decay_func is either pandana2.NoDecay, pandana2.LinearDecay or pandana2.ExponentialDecay which defines how to map a distance along the network to a weight to be used in one of the aggregations. The idea is that observations futher away should matter less when doing each aggregation, or you can use NoDecay to weight them equallly.

aggregation is usually a string like "sum", "mean", "min", "max", "median", "std" (standard deviation). All of the aggregations can be weighted except min and max which will ignore the weights. You can pass a dict of aggregations to compute more than one aggregation for the same input Series.

The method will return a Series which is indexed the same as the nodes on the network. NaN will be returned if there are no observations within the distance requested. A DataFrame will be returned in the case the aggregation parameter is a dictionary.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandana2-0.0.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandana2-0.0.3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pandana2-0.0.3.tar.gz.

File metadata

  • Download URL: pandana2-0.0.3.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pandana2-0.0.3.tar.gz
Algorithm Hash digest
SHA256 813f368f422bb82edc54932a55f857c1fbf7cc501249374144a95371a042d82f
MD5 98a442ad5831dd57e4d74cc64f067b90
BLAKE2b-256 b373a082e551b2fb944f7cb622820198cbef364085cd792c01aeb57ecca4dce1

See more details on using hashes here.

File details

Details for the file pandana2-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pandana2-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pandana2-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1756cc66172c3734574f13e842242f2895987df7ee1c1f48db07258d6ad9b1bd
MD5 14ca2148fd7a6f199268c951bbc3064e
BLAKE2b-256 c6f9c257c5c4dd0aa288649adfb8c1669689357ccdc71de69c18024173da5cfd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page