Datastore won't recognize datetime in CSV files (Matlab 2019b)
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm trying to evaluate a datastore of CSV data that I saved with Matlab using writetable. One column contains datetimes and an example of the files' contents is this:
29-Jul-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.8979
31-Aug-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.9029
30-Sep-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.9106
31-Oct-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.9154
30-Nov-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.9227
30-Dec-1983 00:00:00,BHP AT EQUITY,MOV_AVG_50D,0.9311
I tried the following code and received the subsequent error in the postscript. When I use datastore with "DatetimeType" set to "text," it works, but that is obviously inefficient. Can someone enlighten me on how to get this to work?
Thank You,
Michael
This code works
ds = datastore('tall.csv','DatetimeType','text');
tds = tall(ds);
u = unique(tds.FIELD);
U = gather(u);
This code fails
ds = datastore('tall.csv');
tds = tall(ds);
u = unique(tds.FIELD);
U = gather(u);
The error is
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: 0% complete
Evaluation 0% complete
Error using matlab.io.datastore.TabularTextDatastore/readData (line 77)
Unable to read the DATETIME data using the locale setting for your system: 'en_US'
If the data contains month or day names in a language foreign to this locale, use the 'DateLocale' parameter to specify the correct locale.
Learn more about errors encountered during GATHER.
Error in matlab.io.datastore.TabularDatastore/read (line 120)
[t, info] = readData(ds);
Error in tall/gather (line 50)
[varargout{:}, readFailureSummary] = iGather(varargin{:});
1 件のコメント
Walter Roberson
2019 年 8 月 27 日
Which release are you using?
Which column does FIELD correspond to?
The code seemed to work for me.
採用された回答
その他の回答 (5 件)
Nimit Dhulekar
2019 年 8 月 27 日
Hi Michael,
Are you executing these set of commands from outside the US? If so, the datetime formats available would be different from the ones available in the US. Try the following command:
datetime('29-Jul-1983 00:00:00')
You might quite possibly get an error similar to the one you posted. To get around this issue, you can supply "DatetimeLocale" as a Name-Value pair when constructing the datastore.
ds = datastore('tall.csv','DatetimeLocale','en_US');
Hope that helps!
-Nimit
0 件のコメント
Michael
2019 年 8 月 28 日
1 件のコメント
Walter Roberson
2019 年 8 月 28 日
Try all of the months: there might be a difference only for a few of them.
Michael
2019 年 8 月 28 日
1 件のコメント
Walter Roberson
2019 年 8 月 28 日
And if you use tds.FIELD does it go back to failing? Is it possible that it has decided that tds.FIELD is a datetime ?
Michael
2019 年 8 月 28 日
6 件のコメント
Steve Gardner
2019 年 12 月 5 日
I to have a simular issue CSV files with the date format of yyyy/MM/dd, datastore converts this to MM/dd/yyyy which is fine but for anything after the 12th day of the month it gives the value as NaN, basically it gets the month and day fields mixed up.
I too gave up and converted the CSV file date field to MM/dd/yyyy, just need to remember to do this evey time I get a new CSV file, bit of a pain really.
参考
カテゴリ
Help Center および File Exchange で Tall Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!