To prepare the import into an ERP system of a list of customers (identified from an id) and their related 10 years historical usage data of a system, I needed to shift the data from
customer1, y1:value1, y2:value2, … y10:value10
customer2, y1:value1, y2:value2…
…
to
customer1, y1:value1
customer1, y2:value2
…
customer1, y10:value10
customer2, y1:value1
…
,
There are 889 customers in the file, not finding a way to do this in Excel even usig chatgpt I decided to retrieve from the dust my Julia installation and try to do this excercise.
I come up with this solution, for the sake of knowledge wanted to kindly ask if there is (I’m sure) a better and easier way to get this done
using DelimitedFiles
inv = DelimitedFiles.readdlm("/home/Documents/Cumulative_import.csv", ',';header=false, skipstart=0)
work = zeros(Float64, 8890,2)
for i = 1:10
work[i,1]=inv[1,1]
work[i,2]=inv[1,2]
end
for i = 2:889
for j = ((i-1)*10)+1:((i-1)*10)+10
work[j,1] = inv[i,1]
end
end
v=inv[1,2:11]
work[1:10,2]=v
for i = 2:889
v=inv[i,2:11]
for j = ((i-1)*10)+1:((i-1)*10)+10
if mod(j/10,1) > 0
k=trunc(Int,round(mod(j/10,1);digits=1)*10)
else
k=10
end
work[j,2]=v[k]
end
end
DelimitedFiles.writedlm("/home/Documents/Cumulative_import_export.csv", work,',')
If someone is interested I can provide the origin csv and final result.