Helper to convert SPARQLWrapper results to Pandas dataframes.
Update 10/23/2024 - this library is no longer maintained. SPARQL to dataframe functionality has been added directly to SPARQLWrapper. Please try that library.
See this blog post for examples. You might also be interested in these related examples from Su Labs tutorial.
Directly from PyPi for Python 3.4+.
$ pip install sparql-dataframe
From Github. This should support Python 2.7 as well.
$ pip install git+https://github.com/lawlesst/sparql-dataframe.git
import sparql_dataframe
endpoint = "http://dbpedia.org/sparql"
q = """
SELECT ?label ?wikiPageID
WHERE {
<http://dbpedia.org/resource/Baseball> rdfs:label ?label ;
<http://dbpedia.org/ontology/wikiPageID> ?wikiPageID
}
"""
df = sparql_dataframe.get(endpoint, q)
...
By default, the query will be passed to the server as a GET
request. To pass the query to the server as a POST
request, use the post=True
keyword.
df = sparql_dataframe.get(endpoint, q, post=True)
$ python -m unittest