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

Rik
Rik 2020년 8월 30일
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?

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

 채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 31일

0 개 추천

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)'

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2020년 8월 30일

댓글:

2020년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by