Created a loop including CSVs Topic is solved

questions about GAMS' tools
Post Reply
richard
User
User
Posts: 23
Joined: 8 months ago

Created a loop including CSVs

Post by richard » 5 months ago

Hi all,

Is there any way to refer to the CSV files in a loop?
All my files have systematic names: file1.csv, file2.csv etc. How do I create a loop including all the files?

I am looking for something like this:

set j /1*10/
loop(j,
$include "filej.csv")
How do I go about it?

User avatar
Renger
Posts: 266
Joined: 2 years ago

Re: Created a loop including CSVs

Post by Renger » 5 months ago

Hi Richard

Just starting to learn how to use embededded code in Gams. Here a solution with python:

Code: Select all

$onEmbeddedCode Python:
  f = open('myinclude.inc', 'w')
  for i in range(10):
     f.write('$include'+'" file' + str(i)+'.csv"\n')
  f.close()
$offEmbeddedCode

$include myinclude.inc
Hope this helps
Cheers
Renger

richard
User
User
Posts: 23
Joined: 8 months ago

Re: Created a loop including CSVs

Post by richard » 5 months ago

Hi @Renger , Thanks a lot ! It was very helpful.

Post Reply