layout | title | nav_order | parent | grand_parent |
---|---|---|---|---|
default |
Places within a Place |
6 |
Python |
API |
Signature:
datacommons.get_places_in(dcids, place_type)
Required arguments:
dcids
: A list of nodes to query, identified by their DCID.place_type
: The type of the contained childPlaces
within the given DCIDs to filter by.
Going into more detail on how to assemble the values for the required arguments:
-
dcids
: Data Commons uniquely identifies nodes by assigning them DCIDs, or Data Commons IDs. Your query will need to specify the DCIDs for the nodes of interest. More information about DCIDs is available in the glossary. -
place_type
: This argument specifies the type of place sought in the response. For example, when examining places contained within AmericanStates
, you would be able to selectCity
orCounty
(among others). For a full list of available types, see the place types page.
The method's return value will always be a dict
in the following form:
{
"<dcid>": ["string", ...]
...
}
datacommons.get_places_in(["geoId/10"], "County")
{'geoId/10': ['geoId/10001', 'geoId/10003', 'geoId/10005']}
datacommons.get_places_in(["geoId/15","geoId/02"], "CongressionalDistrict")
{'geoId/15': ['geoId/1501', 'geoId/1502'], 'geoId/02': ['geoId/0200']}
If there is no value associated with the requested property, an empty list is returned:
>>> datacommons.get_places_in(["geoId/1021"], "CongressionalDistrict")
{'geoId/1021': []}
If you do not pass a required positional argument, a TypeError is returned:
>>> datacommons.get_places_in(["geoId/1021"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: get_places_in() missing 1 required positional argument: 'place_type'