Loop Inside class #1373
Unanswered
Nagateja23
asked this question in
Q&A
Replies: 1 comment 5 replies
-
You need to describe how you read the CSV file. That said, you are probably reading the CSV file wrong. Just use one of the method in https://www.geeksforgeeks.org/read-a-csv-into-list-of-lists-in-python/ -- as in, read the whole file into a list of list. Or use Pandas (also described in the URL I linked). |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I have a csv file with some parameters, I want to use those parameters and run my model again and again and store the results of the parameters in a csv.
My current code is
class Opiodmodel(model):
def __init__(self, num_agents=40, width=5, height=5):
.
.
def step(self):
.
.
.
So instead of fixing num_agents,width,height I want to use my csv and take it from there. It has multiple num_agents, widths and heights I want to loop over all of them and store results of all of them...
I tried doing this:
class Opiodmodel(model):
for i in range(len(csvfile)):
n = csvfile['n'][i]
w = csvfile['width'][i]
h = csvfile['height'][i]
def __init__(self, num_agents=n, width=w, height=h):
.
.
def step(self):
.
.
.
But for some reason, the model is only taking in the last row of csv file, it's not iterating over all the values.
Any suggestions are appreciated.
Beta Was this translation helpful? Give feedback.
All reactions