I have a set of attributes (in form of a dataframe). Columns representing agents and rows representing attributes. Not all agents have all attributes, which means I can't manually name and assign the attributes or it'll be messy and hard to interpret later. For example, all agents have age and gender:
class Agent(mesa.Agent):
def __init__(self, unique_id, model):
self.age = model.agent_char[self.unique_id][age]
self.gender = model.agent_char[self.unique_id][gender]
but some have characteristic_1 and some characteristic_2, so I can't write it like this:
self.char_1 = model.agent_char[self.unique_id][char_1]
self.char_2 = model.agent_char[self.unique_id][char_2]
Is there a way to write the code such that a loop reads all available attributes in the column corresponding to the agent, and names the attributes appropriately as well as assign the value of the attribute?
This does not work but it's the idea.
for i, attr in enumerate(model.agent_char.index):
self.attr{i}=model.agent_char[self.unique_id][attr]