Skip to main content

RdfPandas

RdfPandas is a module providing RDF support for Pandas. It consists of two simple functions for Graph to DataFrame conversion and DataFrame to Graph conversion.

Getting Started

For more information about Resource Description Framework (RDF) and Pandas see:

Prerequisites

You will need Python 3 to use Pandas and RdfPandas.

Installation

pip install rdfpandas

Usage

Creating RDF from DataFrame

As of version 1.1.0 NamespaceManager can be supplied to rdflib.to_graph for conversion to Graph.

from rdfpandas.graph import to_graph
import pandas as pd
import rdflib

df = pd.read_csv('to_graph_test.csv', index_col = '@id', keep_default_na = False)
namespace_manager = NamespaceManager(Graph())
namespace_manager.bind('skos', SKOS)
namespace_manager.bind('rdfpandas', Namespace('http://github.com/cadmiumkitty/rdfpandas/'))
g = to_graph(df, namespace_manager)
s = g.serialize(format = 'turtle')

Creating DataFrame from RDF

from rdfpandas.graph import to_dataframe
import pandas as pd
import rdflib

g = rdflib.Graph()
g.parse('to_df_test.ttl', format = 'ttl')
df = to_dataframe(g)
df.to_csv('test.csv', index = True, index_label = "@id")

Gotchas

No special effort is made for dealing with types, so please be aware of Pandas features such as https://pandas.pydata.org/pandas-docs/stable/user_guide/gotchas.html#support-for-integer-na that may result in surprising RDF statements like "10.0"^^<xsd:integer>.

Metadata

Release files for rdfpandas 1.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rdfpandas 1.1.7
File Size Uploaded
rdfpandas-1.1.7.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rdfpandas 1.1.7
File Interpreter ABI Platform
rdfpandas-1.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / rdfpandas-1.1.7.tar.gz

Download URL rdfpandas-1.1.7.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
640bcfd3857c785373edcd1d952131a1a4b699d68ef5b72b631838e2028357b2
BLAKE2b-256 checksum
How to use checksums
979a1eb28f8af4a7f4bec6b2d4b8d71e10284c59321beb218f7fc85bec7b8a52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / rdfpandas-1.1.7-py3-none-any.whl

Download URL rdfpandas-1.1.7-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20f41c93c63021e07fe87759e239903ed8cbac9b938a9626b6c80f192be70aab
BLAKE2b-256 checksum
How to use checksums
49c33aa7f33a2741b840aed3d739a3f3a3127c220aee6263e77f34802b24479e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.1.7 This release

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page