I was wondering how I can translate the following code into python from matlab script? Especially the content within the for loop and the writematrix last line of code, I have been stuck on. This program codes for copying the second row all columns of every excel file within a folder and creates an output excel file in the same folder which has the second row all columns of every excel file within the folder into a single matrix. Thank you, and a happy new year.
clc
clearvars
fileDir = cd;
outfile = 'OUT.xlsx'; %Output file name
fileNames = dir(fullfile(fileDir,'*.CSV'));
fileNames_sorted = natsortfiles({fileNames.name});
M= length (fileNames_sorted);
second_col= [];
for f = 1:M
raw = importdata( fullfile(fileDir, fileNames_sorted{f}));
second_col= [second_col raw(:,2)]; % extract the second column
end
writematrix(second_col,fullfile(cd,outfile))