Datetime format using tabularTextDatastore
이전 댓글 표시
I am importing a large csv file into a data table and I get the following warning:
Warning: Successfully read the date/time text using the format 'MM/dd/uuuu', but their format is ambiguous and could also be 'dd/MM/uuuu'. Specify a format character vector to avoid ambiguity.
Is there a way to set a some global or pass through another variable to get it to stop setting the warning. ds = tabularTextDatastore(fileName,'DatetimeType','datetime','ReadVariableNames',1,'NumHeaderLines',0);
Looking in the tabularTextDatastore help there was no other variable to pass into the function that I could figure out.
댓글 수: 6
Peter Perkins
2018년 8월 3일
I think dpb has it right (as always). It's worth mentioning that if any of the timestamps had been from a day-of-month beyond the 12th, you would not see this warning, because the ambiguity would be resolved.
dpb
2018년 8월 3일
Well, that's heartwarming Peter, but as much as I'd like to claim infallibility, it really isn't so... :)
Nicolas Marx
2018년 10월 9일
Hi, same issue here, I'd like to clearly state the format to avoid ambiguity. I have dates with dd>12 and still get this alert
dpb
2018년 10월 9일
Possibly worth submitting the dataset to TMW support as a "quality of implementation" issue; if the data are interpreted correctly it certainly isn't a bug but if the warning is generated on case it shouldn't be, one would presume TMW would like to know.
However, the doc for datastore object properties states for 'TextscanFormats' that if specific formats aren't provided, " then datastore determines the format of the data fields by scanning text from the first nonheader line in the first file of the datastore." Consequently, I'd guess the warning is based on that scan and not a global revamping of the message after the conversion is complete; the warning is prepared assuming conversion will succeed; then if it fails the error. But, that's a guess, I've not tried to read code nor even tried any empirical testing to try to deduce the logic.
As for specifying the format, just use
ds.TextscanFormats = {'%{MM/dd/uuuu}', ...};
for the fields for all variables. You can first display the existing formats and then update those want to change.
If don't read every variable in the file/datastore, there's the 'SelectedFormats' property that is one format string for each selected variable as alternate way to specify.
Matthew Gold
2018년 10월 10일
dpb
2018년 10월 10일
Attach a (smallish) example of the data and I'll see what happens here. I think for sure the data set should include the first data lines of your actual case.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!