Datetime format using tabularTextDatastore
Mostrar comentarios más antiguos
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 comentarios
Peter Perkins
el 3 de Ag. de 2018
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
el 3 de Ag. de 2018
Well, that's heartwarming Peter, but as much as I'd like to claim infallibility, it really isn't so... :)
Nicolas Marx
el 9 de Oct. de 2018
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
el 9 de Oct. de 2018
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
el 10 de Oct. de 2018
dpb
el 10 de Oct. de 2018
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Time Series Events en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!