The Knowledge Graph Conference Icon
The Knowledge Graph Conference
  • 馃彔Home
  • 馃搮Events
  • 馃懁Members
  • 馃數Announcements
  • 馃數Ask
  • 馃數Ask The Ontologists
  • 馃數Events
  • 馃數Jobs
  • 馃數Promotions
  • 馃數Share
Powered by Tightknit
Ask
Ask

Converting SPARQL Results to CSV for Excel Use

Avatar of Leia D.Leia D.
路May 18, 2022 04:30 PM

Another RDFLib question: is there a way to take SPARQL results and push them to a CSV? I've looked through documentation and it looks possible but I'm still a bit puzzled. (My colleagues want Excel sheets. I know. I know. 馃檭)

10 comments

路 Sorted by Oldest
    • Avatar of nabeel
      nabeel
      路

      if you do something like

      for row in results:
         dict_results = row.asdict()

      the dict_results will be in rdflib variables so like URIRef, Literal, etc so you may need to iterate through the dict and do .toPython() but it might be worth trying and seeing what happens if you write that dict_results to a csv. I haven't tried myself

    • Avatar of Leia D.
      Leia D.
      路

      I see. Thank you, nabeel! The len() is working perfectly btw.

    • Avatar of nabeel
      nabeel
      路

      Glad to hear it!

    • Avatar of Michael G.
      Michael G.
      路

      i dont know much about rdflib, but you can get sparql results as csv from most endpoints. rdflib might be able to execute the query and get the results as csv w/o you having to transform them

    • Avatar of Leia D.
      Leia D.
      路

      Thank you, Michael G.. Working from an endpoint isn't an option unfortunately. That's why I was hoping RDFLib would do it without much issue. I'll definitely use one when I can.

    • Avatar of Michael G.
      Michael G.
      路

      that's not my point. rdflib likely already has code to both read and write results as csv. in which case, you can just pass a result to the csv writer built into the library.

    • Avatar of Leia D.
      Leia D.
      路

      Ok. I see. Thank you.

    • Avatar of Michael G.
      Michael G.
      路

      unless you need a custom csv format, it'll be way easier to just re-use what's in rdflib than to DIY

    • Avatar of Donny W.
      Donny W.
      路

      Leia D. I recorded a <10min video walkthrough addressing your questions about printing RDFLib SPARQL results and exporting to CSV. I hope it's helpful to you. https://www.youtube.com/watch?v=FD_xFFotvxU

      Video thumbnail
    • Avatar of Leia D.
      Leia D.
      路

      Donny W. Wow. Thank you!