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.2.tar.gz (5.4 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.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rdflib_sparql_dataframe-1.0.2.tar.gz
  • Upload date:
  • Size: 5.4 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.2.tar.gz
Algorithm Hash digest
SHA256 8d4a3427f02fa8124dec6e7523bba9fe87ab1a5729bf1015f507935e31973cb9
MD5 045953874dfdfdb8c383fb16ea6d64b6
BLAKE2b-256 a777a8cc5e119b040ef8d283170ff9534ae25df2c26ba9309a3acdb6537ab6e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rdflib_sparql_dataframe-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f71fa1db2537ae99a7e67f6d947f09d253930ee0ba7c49e8f3f9a3e02e034373
MD5 277cec0118536fca8e3bf59360db6cb1
BLAKE2b-256 5161a5c8573b062e79f34a24050c24c9545d8eae6910f6ea20d3fd09f2f46c14

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