Here is my approach based on this answer . See also this notebook for outputs.
import pandas as pd
from rdflib import Graph, URIRef, Namespace
d = {
"source": pd.Series(["Edwin", "Reema", "Ron", "Tomorrow"]),
"target": pd.Series(["football", "karate", "singer", "holiday"]),
"edge": pd.Series(["plays", "plays", "is", "is"]),
}
df = pd.DataFrame(d)
g = Graph()
n = Namespace('http://example.org/foo/')
for inded, row in df.iterrows():
# add triple to rdf-graph
g.add((URIRef(n+row["source"]), URIRef(n+row["edge"]), URIRef(n+row["target"])))
print(g.serialize(format='turtle'))
With some additional visualization code (based on https://stackoverflow.com/a/61483971/333403 ) you arrive at:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.