0
$\begingroup$

I have two lists of data here: dm and dmHalo (see attached image). Theses are the same lists, the only difference is that dm was exported to a csv file and then reimported, while dmHalo was generated in the notebook session.

When I go to run an interpolation on the data set the interpolation does not recognize the csv imported data, as seen in the error message. I assume this is due to a change in formatting, but I am at a loss at how to revert to the native format.

Does anyone have an idea of how to do this?

Thanks you for your help!

enter image description here

$\endgroup$
11
  • $\begingroup$ Have you check with Dimensions[] that both object have the same dimensions? $\endgroup$
    – Drod
    May 20, 2021 at 20:15
  • 1
    $\begingroup$ And Head /@ {dm, dmHalo} $\endgroup$ May 20, 2021 at 21:59
  • 1
    $\begingroup$ Try First[dm] // InputForm and if there are quotes (") around the numbers, you've imported text instead of numbers. How did you export and import to CSV (Export and Import)? Please show the code you used. $\endgroup$
    – creidhne
    May 20, 2021 at 22:24
  • $\begingroup$ @Drod Thank you for your suggestion. Yes Dimension returns {} for dm and {30,2} for dmHalo. $\endgroup$
    – asorlik
    May 21, 2021 at 19:11
  • $\begingroup$ @Rohit This returns String and List. $\endgroup$
    – asorlik
    May 21, 2021 at 19:16

2 Answers 2

0
$\begingroup$

Summary of issue: dmHalo and dm in the original post were inner parts of a nested data structure in the format {{i, {{j,k,l},{m,n,o},{...}}}}. The problem is that the export formats--.csv, .dat, .txt.-- regardless of keyword--"Data","Table","List"--would convert the inner lists into strings in a way that is irreversible (at least from what I have tried i.e. using ToExpression on the resulting string).

SOLUTION: Using Put and Get (Mathematica: issues storing nested list on disk) has seemed to resolve the issue and I now can recover the list format of the inner nested lists. As seen in the images, the export process converts the inner list to a string, whereas with the Put and Get commands the list format is preserved.

enter image description here

enter image description here

$\endgroup$
0
$\begingroup$

The nested lists are saved as strings so ToExpression has to be mapped.

data = {{1, {{2, 3, 4}, {5, 6, 7, {8, 9}}}, 10, {11, 12}}};

export = ExportString[data, "CSV"];
import = ImportString[export, "CSV"];

importData = import // Map[ToExpression]
importData == data
(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.