RDF support for Pandas
Project description
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:
Pandas: https://pandas.pydata.org/
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>.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rdfpandas-1.1.7.tar.gz.
File metadata
- Download URL: rdfpandas-1.1.7.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
640bcfd3857c785373edcd1d952131a1a4b699d68ef5b72b631838e2028357b2
|
|
| MD5 |
7a8a84d2a762c6866ae67221c6a71af7
|
|
| BLAKE2b-256 |
979a1eb28f8af4a7f4bec6b2d4b8d71e10284c59321beb218f7fc85bec7b8a52
|
File details
Details for the file rdfpandas-1.1.7-py3-none-any.whl.
File metadata
- Download URL: rdfpandas-1.1.7-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20f41c93c63021e07fe87759e239903ed8cbac9b938a9626b6c80f192be70aab
|
|
| MD5 |
cc1acd3c51e8b36767bda857233032d3
|
|
| BLAKE2b-256 |
49c33aa7f33a2741b840aed3d739a3f3a3127c220aee6263e77f34802b24479e
|