Message Boards Message Boards

0
|
6113 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Exporting and importing a table

The following is a small piece of a huge table I need to Export as a file, to get it back later by using Import.

  ms= {{1689, DateObject[{2015, 3, 25}, 
      TimeObject[{0, 0, 0.}, TimeZone -> -3.], 
      TimeZone -> -3.], 41, 2, 53, 5, 13, 27, 
     3.54771*10^7, 2, {"REDENÇÃO", "SÃO PAULO"}, {"PA", "SP"}, 
     3.61023*10^6, 185, 11227.2, 9634, 307.98, "NÃO", 0., 1.9*10^7, 
     1.39854*10^7}, {1690, 
     DateObject[{2015, 3, 28}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], 
      TimeZone -> -3.], 24, 45, 53, 35, 26, 21, 
     4.58805*10^7, 0, "", "", 0., 63, 42636.4, 5708, 672.26, "SIM", 
     1.88354*10^7, 2.5*10^7, 1.46923*10^7}};

Exporting as "Table" or "Data" resulted in loss of data (check {"REDENÇÃO", "SÃO PAULO"}}. Exporting as "Text" resulted in loss of structure (the recovery data is not a table anymore).

Can someone help me?

Going further, is it possible to import the table with the DateObject in the format such as:

enter image description here?

5 Replies

Hi,

I am a little bit confused: Is not the solution as simple as using Put and Get, I mean can't you export and import just any expression with these commands? In the case of your example:

ClearAll["Global`*"]

msOut = {{1689, 
    DateObject[{2015, 3, 25}, TimeObject[{0, 0, 0.}, TimeZone -> -3.],
      TimeZone -> -3.], 41, 2, 53, 5, 13, 27, 3.54771*10^7, 
    2, {"REDENÇÃO", "SÃO PAULO"}, {"PA", "SP"}, 3.61023*10^6, 185, 
    11227.2, 9634, 307.98, "NÃO", 0., 1.9*10^7, 1.39854*10^7}, {1690, 
    DateObject[{2015, 3, 28}, TimeObject[{0, 0, 0.}, TimeZone -> -3.],
      TimeZone -> -3.], 24, 45, 53, 35, 26, 21, 4.58805*10^7, 0, "", 
    "", 0., 63, 42636.4, 5708, 672.26, "SIM", 1.88354*10^7, 2.5*10^7, 
    1.46923*10^7}};

(* dump to file: *)
msOut >> "ms"

(* reading back in: *)
msIn = << "ms";

(* check for differences: *)
msIn - msOut

(*  out:  \
{{0,0,0,0,0,0,0,0,0.`,0,{0,0},{0,0},0.`,0,0.`,0,0.`,0,0.`,0.`,0.`},{0,\
0,0,0,0,0,0,0,0.`,0,0,0,0.`,0,0.`,0,0.`,0,0.`,0.`,0.`}}
*)

Or am I missing the point?

Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 9 years ago

The same thought occurred to me this morning when I realized that I was assuming, without cause, that a table format was needed for some other tool. If the only need is to store data on disk for later use by a notebook Put and Get is a great solution.

POSTED BY: David Keith

That was absolutely great. Thanks a lot.

Posted 9 years ago

I believe the root cause of the problem is the inconsistent row format. The two rows of data you post have different structures. In the first row, columns 10 and 11 each contain a 2 element list; in the second row they contain strings. This is especially a problem for exporting as a table, like csv or tsv, because what is needed is a 2 dimensional array of atomic objects. If this is the only structure issue, the data could be reprocessed to fix it. For example, when a two element list of strings is encountered on the 2nd level it could be replaced by a single string which is the two strings joined with a delimiter of some kind. But, if this data was generated in prior computation, it would perhaps be better to just correct the issue there. Once done, Export in table format should work fine.

POSTED BY: David Keith

Hi David,

I tried to avoid the solution proposed in your advice, but it seems that there is no other easy way to do that. So I built two functions to handle the problem. The first function converts the lists inside the table to single strings (as you suggested) and then exports the whole table to a file. The second function undoes the work of the first function.

Thanks a lot for your help.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract