Мне нужна помощь в преобразовании сценария Matlab в Python. Скрипт переупорядочивает данные от календарного года до года воды. Я хотел бы научиться делать что-то подобное с Python и Pandas и использовать DataFrame. Спасибо за ваше время.
% Beginning of script code
% Initialize the annualflow matrix to have 10 rows and 2 columns (date and
% discharge)
annualflow = zeros(10, 2);
% Initialize counter
yearcount = 1;
for year= 2003:2012
% Find the serial date at the start and end of each water year.
% Water years start on 10/1 of the previous year and end on 9/30
startdate = datenum(year-1,10,01);
enddate = datenum(year,09,30);
% Assign the water year number to column 1
annualflow(yearcount,1) = year;
% Loop through the entire daily data array. If the date is within the
% current water year, add the daily discharge to the cumulative sum.
numdays = 0;
for i=1:size(WabashRiver)
if(WabashRiver(i,1) >= startdate && WabashRiver(i,1) <= enddate)
% Count the number of days in each year.
numdays = numdays + 1;
% Find the cumulative sum of discharge for this year.
annualflow(yearcount,2) = annualflow(yearcount,2) + WabashRiver(i,2);
end
end
% Divide by the number of days in the year to get a daily discharge
% rate.
annualflow(yearcount,2) = annualflow(yearcount,2)/numdays;
% Increase the row index, this will take on values 1 - 10.
yearcount = yearcount + 1;
end
% End of script code