I have this Dataframe for a transportation problem.
Unnamed: 0 Unnamed: 1 c1 c2 c3 c4 c5 capacity
0 NaN p1 4 5 6 8 10 500.0
1 NaN p2 6 4 3 5 8 500.0
2 NaN p3 9 7 4 2 4 500.0
3 demand NaN 80 270 250 160 180 NaN
I have changed the column name like this,
df.columns = ['Demand', 'Plant', 'c1', 'c2', 'c3', 'c4', 'c5', 'capacity']
I want to make a dictionary like this,
d = {c1:80, c2:270, c3:250, c4:160, c5:180} # customer demand
M = {p1:500, p2:500, p3:500} # factory capacity
I = [c1,c2,c3,c4,c5] # Customers
J = [p1,p2,p3] # Factories
cost = {(p1,c1):4, (p1,c2):5, (p1,c3):6,
(p1,c4):8, (p1,c5):10, ......
}
For 1st case, I have used the following code,
M = df.set_index('Plant')['capacity'].to_dict()
It is giving me,
{'p1': 500.0, 'p2': 500.0, 'p3': 500.0, nan: nan}
I don't want any NaN value. Please help to find this total dictionary (d, M and cost) in a generic way without a NaN.