0

Quick Aside So, I'm a bit of a rookie with Python; therefore forgive my incorrect ways of describing things AND ask me questions if I don't provide enough information.

Ask my title indicates, I'm attempting to bring in a data set that is Lisp data structure. I'm trying to start small and work with a smaller data set (as I'm going to be dealing with much larger eventually) however, I'm unclear as to how I should set up my separators for my pandas

So, I'm bringing in a .dat file from a lisp data structure, and reading it with pandas (or attempting to). My goal, is to try and have it be a normal data set, where I can separate a given, say function, with its' respected outputs.

My Lisp Data set looks like the following:

(setf nameoffile?'
((function-1 output1) (function-2 output2 output3 output4) (function-3 output5 output 6 output7...)
(function-4 output)
...
(function-N outputN outputM ... )) )

Hopefully this is not too cryptic. Please, let me know if I'm not providing enough information. Lastly, my goal is to have all of the functions, lets say in a row and have the outputs read across the row in a pandas dataframe (since I'm used to that); for example:

function-1: output1
function-2: output2 and so on and so forth...

Again, please let me know if I'm a bit confusing, or did not provide enough information. Thank you so much in advance!

EDIT: My specific question is how can I insert this somewhat ambiguous lisp data structure into a pandas dataframe? Additionally, I dont know how to modify what I want into their desired rows and on how to separate them (delimiter/sep = ?). When I insert this via pandas, I get a very mumble jumbled dataframe. I think a key issue is how do I separate them appropriately?

  • 1
    And your question is? – Renzo Jul 19 '17 at 20:12
  • 1
    Your question is unclear. However, since you, _apparently_, want to load **data** into **pandas**, the answer is, _probably_, [CSV](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html). – sds Jul 19 '17 at 20:24
  • Thanks for your response! I added an edit with a more "specific" question. Hopefully that helps. Thanks for the help again! – cross12tamu Jul 19 '17 at 20:35
  • 4
    It's probably easier to make a small Lisp program that writes the data in a suitable format than it is to write Lisp parser (even if you only need to handle a few special cases). – molbdnilo Jul 20 '17 at 08:41

2 Answers2

1

As noted by @molbdnilo and @sds, it's probably easier to export data from lisp in a common format and then import them in Python using an existing parser.

For example you can save them to CSV file from Lisp, using the cl-csv library that is also available on quicklisp.

As you can see from cl-csv tests, you can get a csv string from you data using the write-csv function:

(write-csv *your-data-rows* :always-quote t)

Or, if you want to proceed line-by-line, you can use write-csv-row function.

Then will be easy to save the resulting string into a file and read this CSV from Python.

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
  • This makes a lot of sense. Thanks for the clarification and instruction! I'll be giving it a whirl in just a bit! – cross12tamu Jul 24 '17 at 15:36
0

If your Lisp program isn't already too large, consider rewriting it in Hy. Hy is a Lisp dialect, so you can continue writing in Lisp. But also,

Hy maintains, over everything else, 100% compatibility in both directions with Python itself.

This means you can use Python libraries when writing Hy, and you can write a module in Hy to use in Python.

I don't know how your project is setup (and I don't know Pandas), but perhaps you can use this to communicate directly with Pandas?

Quelklef
  • 1,999
  • 2
  • 22
  • 37