Hi Renger,
Thanks a lot, I got it. You have been so helpful.
I am sorry if I bother you, but you have a small example of writting results to a CSV file?
Kind regards.
Beginner Question: Using csv as an input
Re: Beginner Question: Using csv as an input
I am trying to read the following CSV file (hourlyDataInput3.csv):
p,Demand,WindGen
1,17.64,4.52
2,21.13,3.33
3,22.48,5.74
4,22.01,4.81
The code is:
* definitions
sets
p /1*4/
;
parameters
pDemand (p)
pWindGen (p)
;
table Hourly(*,*) "Demand and Wind Generation per year"
$ondelim
$include hourlyDataInput3.csv
$offdelim
;
pDemand(p) = Hourly (p,'Demand');
pWindGen(p) = Hourly (p,'WindGen');
display pDemand, pWindGen;
However, I have mistakes. Could you help me to fix this. Thanks in advance.
p,Demand,WindGen
1,17.64,4.52
2,21.13,3.33
3,22.48,5.74
4,22.01,4.81
The code is:
* definitions
sets
p /1*4/
;
parameters
pDemand (p)
pWindGen (p)
;
table Hourly(*,*) "Demand and Wind Generation per year"
$ondelim
$include hourlyDataInput3.csv
$offdelim
;
pDemand(p) = Hourly (p,'Demand');
pWindGen(p) = Hourly (p,'WindGen');
display pDemand, pWindGen;
However, I have mistakes. Could you help me to fix this. Thanks in advance.
Re: Beginner Question: Using csv as an input
Hi
This runs fine on my computer. Did you include the correct csv file? What is the error you get?
Cheers
Renger
This runs fine on my computer. Did you include the correct csv file? What is the error you get?
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Beginner Question: Using csv as an input
Hi Renger,
You are rigth, I found the problem. I had the input files in a different directory.
I am sorry to bother again. Now, I want o read a CSV file that does not have any header. I mean, it is bidimensional (i,j) and it has just the values for each i,j
The file (Cost.csv) is like:
1,1,1,1,1
0,1,0,1,0
1,1,1,1,1
And my program is like this:
sets
i generation units /1*3/
j time periods /1*5/
;
table Cdata(i,j) cost for unit i at period j
$ondelim
$include Cost.csv
$offdelim
;
display Cdata;
However, I am having some errors about duplicated values.
By the way, do you have a short example of writing to CSV files?
Thanks a lot
You are rigth, I found the problem. I had the input files in a different directory.
I am sorry to bother again. Now, I want o read a CSV file that does not have any header. I mean, it is bidimensional (i,j) and it has just the values for each i,j
The file (Cost.csv) is like:
1,1,1,1,1
0,1,0,1,0
1,1,1,1,1
And my program is like this:
sets
i generation units /1*3/
j time periods /1*5/
;
table Cdata(i,j) cost for unit i at period j
$ondelim
$include Cost.csv
$offdelim
;
display Cdata;
However, I am having some errors about duplicated values.
By the way, do you have a short example of writing to CSV files?
Thanks a lot
Re: Beginner Question: Using csv as an input
Hi
You need the labels for the table (e.g. i and j) otherwise Gams assumes the first column and row as set elements (therefore the duplicates).
If you want to write a csv file you can do stuff like this
Have a closer look at the put documentation.
Cheers
Renger
You need the labels for the table (e.g. i and j) otherwise Gams assumes the first column and row as set elements (therefore the duplicates).
If you want to write a csv file you can do stuff like this
Code: Select all
file myfile /output.csv/;
put myfile;
loop(i,
loop(j,
put i.tl ...
etc.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Beginner Question: Using csv as an input
Hi,
Thank you. Is there any other way to read the file? I mean, without the labels?
Kind regards.
Thank you. Is there any other way to read the file? I mean, without the labels?
Kind regards.
Re: Beginner Question: Using csv as an input
Not that I am aware of.
Renger
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Beginner Question: Using csv as an input
Thanks a lot Renger!!!