Wikidata SPARQL queries in Jupyter

I wanted to query all events in a certain area from Wikipedia (e.g. members of occurrence with a location within a region).

Wikidata and SPARQL language can be used through query.wikidata.org. This is a notebook where I queried wikidata and converted the results into a pandas DataFrame:

The SPARQL query (example: Events in Nevada):

#title: All events in Nevada, based on distance query (400km)
SELECT ?event ?eventLabel ?date ?location
WITH {
  SELECT DISTINCT ?event ?date ?location
  WHERE {
    # find events
    wd:Q1227 wdt:P625 ?nevada. 
    ?event wdt:P31/wdt:P279* wd:Q1190554.
           # wdt:P17 wd:Q30;
    # with a point in time or start date
    OPTIONAL { ?event wdt:P585 ?date. }
    OPTIONAL { ?event wdt:P580 ?date. }
    ?event wdt:P625 ?location.
    FILTER(geof:distance(?location, ?nevada) < 400).
  }
  LIMIT 1000
} AS %i
WHERE {
  INCLUDE %i
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

117 events queried from wikidata that are located in Nevada