After using the datastore function, how to change the value in the 'csv' ?

조회 수: 2 (최근 30일)
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

채택된 답변

Aaditya Kalsi
Aaditya Kalsi 2015년 11월 3일
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.
  댓글 수: 1
Jingyu Ru
Jingyu Ru 2015년 11월 4일
Thank you for your helping. Do you mean in this 'datastore' framework or even in this release of Matlab, I have to save every partition csv/txt files respectively and assemble them together using other software after analyzing all the data?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Datastore에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by