Loading...
Loading...
Work with Data Commons, a platform providing programmatic access to public statistical data from global sources. Use this skill when working with demographic data, economic indicators, health statistics, environmental data, or any public datasets available through Data Commons. Applicable for querying population statistics, GDP figures, unemployment rates, disease prevalence, geographic entity resolution, and exploring relationships between statistical entities.
npx skill4agent add jackspace/claudeskillz datacommons-clientpip install "datacommons-client[Pandas]"pip install datacommons-clientreferences/observation.mdfrom datacommons_client import DataCommonsClient
client = DataCommonsClient()
# Get latest population data
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06"], # California
date="latest"
)
# Get time series
response = client.observation.fetch(
variable_dcids=["UnemploymentRate_Person"],
entity_dcids=["country/USA"],
date="all"
)
# Query by hierarchy
response = client.observation.fetch(
variable_dcids=["MedianIncome_Household"],
entity_expression="geoId/06<-containedInPlace+{typeOf:County}",
date="2020"
)references/node.md# Discover properties
labels = client.node.fetch_property_labels(
node_dcids=["geoId/06"],
out=True
)
# Navigate hierarchy
children = client.node.fetch_place_children(
node_dcids=["country/USA"]
)
# Get entity names
names = client.node.fetch_entity_names(
node_dcids=["geoId/06", "geoId/48"]
)references/resolve.md# Resolve by name
response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"],
entity_type="State"
)
# Resolve by coordinates
dcid = client.resolve.fetch_dcid_by_coordinates(
latitude=37.7749,
longitude=-122.4194
)
# Resolve Wikidata IDs
response = client.resolve.fetch_dcids_by_wikidata_id(
wikidata_ids=["Q30", "Q99"]
)resolve_response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"]
)
dcids = [r["candidates"][0]["dcid"]
for r in resolve_response.to_dict().values()
if r["candidates"]]variables = client.observation.fetch_available_statistical_variables(
entity_dcids=dcids
)response = client.observation.fetch(
variable_dcids=["Count_Person", "UnemploymentRate_Person"],
entity_dcids=dcids,
date="latest"
)# As dictionary
data = response.to_dict()
# As Pandas DataFrame
df = response.to_observations_as_records()Count_PersonCount_Person_FemaleUnemploymentRate_PersonMedian_Income_HouseholdCount_DeathMedian_Age_Person# Check what variables are available for an entity
available = client.observation.fetch_available_statistical_variables(
entity_dcids=["geoId/06"]
)
# Or explore via the web interface
# https://datacommons.org/tools/statvarresponse = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all"
)
# Convert to DataFrame
df = response.to_observations_as_records()
# Columns: date, entity, variable, value
# Reshape for analysis
pivot = df.pivot_table(
values='value',
index='date',
columns='entity'
)export DC_API_KEY="your_key"client = DataCommonsClient(api_key="your_key")client = DataCommonsClient(url="https://custom.datacommons.org")references/references/observation.mdreferences/node.mdreferences/resolve.mdreferences/getting_started.mdfetch_available_statistical_variables()filter_facet_domainsreferences/