Import data with 1000 seperator
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I want to import data from a csv file with numeric values separated by a thousand separator.
Ex: 1 000,00
I use readtable function with option opts = setvaropts(opts, "ACC_Z", "ThousandsSeparator", " ");
But it doesn't work and I get the value 1 instead of 1000 in the imported table.
Should I do anything else?
Thanks.
4 comentarios
dpb
el 9 de Oct. de 2023
Editada: dpb
el 9 de Oct. de 2023
That's the Q? -- is the posted example one or two elements of "1 000,00" --> 1000.00 or as OP says it is a CSV file, "1 000,00" --> 1000, 0??? As posted, it's indeterminate. One may presume one or the other and the first is more likely to be the case and it isn't actually a real CSV file format, but just unable to tell for sure without more info...and, of course, posting the actual file is always the best way to resolve such conundrums.
Respuestas (1)
dpb
el 9 de Oct. de 2023
Editada: dpb
el 9 de Oct. de 2023
It's still questionable what is the content of actual file, but it appears one can make the OP's presumption come true...now whether that's what the file content really is or not is anybody's guess.
l="1 000,00"; % assume a record
writelines(l,'Test.csv') % create a file
type Test.csv % see what we made for sure
opt=detectImportOptions('Test.csv') % create an import object
opt.Whitespace=''; % the blank isn't whitespace here...
opt.VariableTypes(1)={'double'}; % try to convince it should be a number besides
opt=setvaropts(opt,{'Var1'},'ThousandsSeparator'," "); % but a separator.
tD=readtable('Test.csv',opt) % and see what happens...
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!