Get Statistical Time Series for a Place

datacommons.get_stat_series(place, stat_var, measurement_method=None,observation_period=None, unit=None, scaling_factor=None)

Returns a dict mapping date to value for a place based on the stat_var, with optional filter parameters.

See the full list of StatisticalVariables.

Arguments

  • place (str): The dcid of the Place to query for.

  • stat_var (str): The dcid of the StatisticalVariable.

  • measurement_method (str): (Optional) The dcid of the preferred measurementMethod for the stat_var.

  • observation_period (str): (Optional) The preferred observationPeriod for the stat_var. This is an ISO 8601 duration such as P1M (one month).

  • unit (str): (Optional) The dcid of the preferred unit for the stat_var.

  • scaling_factor (int): (Optional) The preferred scalingFactor for the stat_var.

Returns

A dict mapping date(str) to the statistical value (float).

If no statistical value can be found for the place with the given parameters, an empty dictionary is returned.

Be sure to initialize the library. Check the Python library setup guide for more details.

You can find a list of StatisticalVariables with human-readable names here.

Examples

We would like to get the male population in Arkansas

>>> import datacommons as dc
>>> dc.get_stat_series("geoId/05", "Count_Person_Male")
{
  "2013": 1439862,
  "2014": 1447235,
  "2015": 1451913,
  "2016": 1456694,
  "2017": 1461651,
  "2018": 1468412,
  "2011": 1421287,
  "2012": 1431252
}

In the next example, the parameter observation_period='P3Y' overly constrains the request, so the API does not return a value:

>>> dc.get_stat_series('geoId/06085', 'Count_Person', observation_period='P3Y')
{}