How to handle changes to imported csv files

I am currently using readtable with DelimitedTextImportOptions to extract specific variables only (i.e total deposits) from multiple csv files of financial institutions to do some analysis. These files all have the same structure(same number of rows and columns and same variable names). What functionality can use to handle any changes to these csv files? i.e a new column or row is added to them? I would still only be interested in specific variables though like total depsits

2 Comments

Without knowing what kind of changes you mean, your current method and an example file it is hard to tell how robust your methods are.
I have attached a sample of the files and the .m file to import the total deposits and loans for each institution. I have a folder for each month containing all csv files for that particular month. Each csv file corresponds to an institution for a particular month. here is how I ge the loan deposit ratio for all banks for a given set of month(s)
function LDR = LoanDepRatio(MonthDirectory)
for k=1:numel(MonthDirectory)
MonthlyStrucFiles = dir(char(MonthDirectory(k)));
MonthlyArrayFiles = {MonthlyStrucFiles.name};
for j=3:numel(MonthlyArrayFiles) % the first two elements of MonthlyArrayFiles contain '.' and '..' hence I started at 3
MonthlyDeposits(j-2,k) = ImportDeposit(char(MonthlyArrayFiles(1,j)));
MonthlyLoans(j-2,k) = importLoan(char(MonthlyArrayFiles(1,j)));
LDR(j-2,k) = (MonthlyLoans(j-2,k) / MonthlyDeposits(j-2,k));
end
end
end
As there are 10 variables in each file. lets say an 11th variable i.e NCDsQ is added to the csv files by the institutions but this variable is unrelated to my analysis, how should I handles such changes?

Sign in to comment.

 Accepted Answer

Use detectImportOptions on each file. The option for selected variables can take a cell array of character vectors that are the variable names. If you are using r2019b or later and give the PreserveVariableNames option then the variable name can be 'Total(7)'

More Answers (0)

Community Treasure Hunt

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

Start Hunting!