Import and Export for CSV are both broken in Mathematica

Posted by dreeves on Stack Overflow See other posts from Stack Overflow or by dreeves
Published on 2010-05-04T21:02:18Z Indexed on 2010/05/05 4:48 UTC
Read the original article Hit count: 326

Filed under:
|
|
|
|

Consider the following 2 by 2 array:

x = {{"a b c", "1,2,3"}, {"i \"comma-heart\" you", "i \",heart\" u, too"}}

If we Export that to CSV and then Import it again we don't get the same thing back:

Import[Export["tmp.csv", d]]

Looking at tmp.csv it's clear that the Export didn't work, since the quotes are not escaped properly.

According to the RFC which I presume is summarized correctly on Wikipedia's entry on CSV, the right way to export the above array is as follows:

a b c, "1,2,3"
"i ""heart"" you", "i "",heart"" u, too"

Importing the above does not yield the original array either. So Import is broken as well.

I've reported these bugs to [email protected] but I'm wondering if others have workarounds in the meantime.

One workaround is to just use TSV instead of CSV. I tested the above with TSV and it seems to work (even with tabs embedded in the entries of the array).

© Stack Overflow or respective owner

Related posts about mathematica

Related posts about csv