'I am trying to assign data from a CSV file to parameters in python?

I am trying to read in CSV files to my code, and assign the data from the files to parameters in my model.

The following CSV files are read into my model.

distances = pd.read_csv('distances.csv', index_col = "Pickup Location") # My csv file with distances between each location #
    distances

enter image description here

waste = pd.read_csv('waste_amount.csv', index_col = "Location") # Waste Amount at each location #
waste

enter image description here

The following parameters are what I want to assign my data to. distances.csv to model.D and waste_amount.csv to model.Q

# Parameters #
model.Q = Param(model.J)                                     # Waste amount of bin #
model.D = Param(model.I, model.J, domain = PositiveReals)    # Distance between nodes #

Where from my datafiles-> D:(i,j): D(0,1) = 9.41, and Q(j): Q(1) = 2

I am wondering could someone point me in the right direction on how to achieve this? If you need any more information, please let me know.

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source