Skip to main content

Export results from an rdflib SPARQL query into a `pandas.DataFrame`, using Python types.

Project description

RDFLib SPARQL DataFrame

Export results from an rdflib SPARQL query into a pandas.DataFrame, using Python types.

Taken from https://github.com/RDFLib/sparqlwrapper/issues/125#issuecomment-704291308 resp. https://github.com/RDFLib/rdflib/issues/1179#issuecomment-704299074 .

Install

pip install rdflib-sparql-dataframe
# or
poetry add rdflib-sparql-dataframe

Use

from rdflib import Graph
from rdflib_sparql_dataframe import sparql_results_to_df

data = """
@prefix ex: <https://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

ex:Petra a foaf:Person ;
  foaf:name "Petra" ;
  foaf:knows ex:Peter .

ex:Peter a foaf:Person ;
  foaf:name "Peter" .
"""

query = """
prefix foaf: <http://xmlns.com/foaf/0.1/>
select ?person ?name ?friend ?friendname {
  ?person foaf:name ?name ;
    foaf:knows ?friend .
  ?friend foaf:name ?friendname .
}
"""

graph = Graph()
graph.parse(data=data)

dataframe = sparql_results_to_df(graph.query(query))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rdflib_sparql_dataframe-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rdflib_sparql_dataframe-1.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file rdflib_sparql_dataframe-1.0.1.tar.gz.

File metadata

  • Download URL: rdflib_sparql_dataframe-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.13.5-200.fc41.x86_64

File hashes

Hashes for rdflib_sparql_dataframe-1.0.1.tar.gz
Algorithm Hash digest
SHA256 aefbe4978d9aa800251f6a7b5e8f22246ce91210d74ecbf8830a83573b5e7b98
MD5 c6fcd4cb0d48155cb6b871519928747b
BLAKE2b-256 a4645e920f8864cac31340e7240bddcf2059c510c73f08109ccdfbad9b1c9d03

See more details on using hashes here.

File details

Details for the file rdflib_sparql_dataframe-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rdflib_sparql_dataframe-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7cdaa5f7eea56b88ab677aaf64749f0db106a4fc953078645abfbb0d8299afa
MD5 536e8039bc813fa6922f6e1d2177dd6f
BLAKE2b-256 b71095c16aecb1ceba700b7af9d0cfd6e5b4562d92a3a1ee88e07aa2e0e0b966

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page