After using the datastore function, how to change the value in the 'csv' ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jingyu Ru
am 3 Nov. 2015
Bearbeitet: Jingyu Ru
am 4 Nov. 2015
I find it is useful to read the 'csv' file with the datastore function. Especially for the big data.
After analysis the data, I want to change some value in the 'TabularTextDatastore' data. What function could I use?
For example:
code:
ds = datastore('airlinesmall.csv','TreatAsMissing','NA',... 'SelectedVariableNames','ArrDelay','ReadSize',1000);
sums = [];
counts = [];
while hasdata(ds)
T = read(ds);
% change the year value less than 1997 to 0 %
end
0 Kommentare
Akzeptierte Antwort
Aaditya Kalsi
am 3 Nov. 2015
The datastore cannot reflect the changed values because it simply reads the data from the file into a table.
If you want to store the changed values, you want to write the modified table back out.
Example:
while hasdata(ds)
[T, info] = read(ds);
T.DateValue(T.DateValue < 1997) = 0;
filename = ['newfolder/newfile_', num2str(info.Offset), '.txt'];
writetable(T, filename);
end
newds = datastore('newfolder/*.txt');
While this may not be the most efficient, it certainly will work.
Hope that helps.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Datastore finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!