4
$\begingroup$

14.1

data = Import["file.csv"]
data[[2]]
{"2019-01-09T01:00:00+02:00", 1.276, 1.2782, 1.2757, 1.2779, 0.0019, 0.0025, 0.0022, -0.0003}

14.2 14.2 Import now takes x2 time due to converting 1st element. Seems like I need to use Import["file","RawData"]. Editing every notebook is inconvenient...

I tried to modify init.m with SetOptions[Import,"RawData"] but that's invalid replacement rule.

Looking for advice. How to make it normal again. Thanks.

$\endgroup$
1
  • 1
    $\begingroup$ The whole release (almost) is about Tabular[]... Hope they'll fix it in 15 or 16. Why suddenly certain time strings becomes date objects and others not? $\endgroup$ Commented Jan 28 at 6:59

5 Answers 5

5
$\begingroup$

To set the default import element for "CSV", use e.g. SetFileFormatProperties["CSV", "DefaultImportElement" -> "RawData"]..

Disclaimer, I while I do work at WRI, this is my personal opinion too, I'd try the new Tabular element!

The new Tabular[] object is columnar end efficient and has types for columns, so those dates will be quite efficient.

$\endgroup$
4
$\begingroup$

Create a CSV file with two columns:

dates = RandomDate[Today, 5];
reals = RandomReal[10, 5];
Export["file.csv", Transpose[{dates, reals}]]

By default the first column is parsed as Date and the second column is parsed as Real64:

In[26]:= Import["file.csv", "ColumnTypes"]

Out[26]= {"Date"::["Integer64", "Nanosecond" -> "Instant", Automatic, "UTC"], "Real64"}

Change the type of the first column using "Schema" option:

In[27]:= Import["file.csv", "Schema" -> "ColumnProperties" -> {<|"ElementType" -> "String"|>, <|"ElementType" -> "Real64"|>}]

Out[27]= {{"2025-01-28T17:18:54.313+01:00", 5.24222},
 {"2025-01-28T04:29:01.489+01:00", 2.09629},
 {"2025-01-28T13:13:44.959+01:00", 5.8431},
 {"2025-01-28T08:21:34.543+01:00", 5.4883},
 {"2025-01-28T12:30:55.674+01:00", 3.85484}}
$\endgroup$
3
$\begingroup$

It seems you can fiddle with "DateStringFormat" option:

ImportString["2019-01-09T01:00:00+02:00, 1.276, 1.2782", "CSV", "DateStringFormat" -> {""}]
(* {{"2019-01-09T01:00:00+02:00", 1.276, 1.2782}} *)
$\endgroup$
0
$\begingroup$

Thanks for the suggestions. I thought that "RawData" will solve the issue, but it interprets numeric values as strings..

I was able to come up with the following variants:

  1. In 14.1 convert .csv to .wl

    data = Import["D:\6B_1H.csv"] Export["6B_1H.wl", data]

Imports adequately in 14.2 (1st column is a string, as it should be)

  1. 14.2

    data1 = Import["D:\6B_1H.csv", "DateStringFormat" -> {""}][[;;, 1]]

    data2 = Import["D:\6B_1H.csv",][[;;, 2;;]]

    data3 = Flatten[#] & /@ Transpose[{data1, data2}]

  2. Continue using 14.1

Thanks, Wolfram Team, for a very convenient update.

$\endgroup$
1
  • 3
    $\begingroup$ There is also an option "Backend" -> "Table" to get back to the 14.1 behavior which was documented in possible issues. $\endgroup$ Commented Jan 28 at 16:09
0
$\begingroup$

I ran into a similar issue and found that @GenericAccountName's suggestion worked well for me. I simply added the optional argument

Import["file.csv", "Backend" -> "Table"]
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.