Converting my gurobi dict to dataframe
Answered
This gets converted to
But I need to work with the values and not just the tuples
How to get values purely instead of tuples
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Ishani,
There are several ways to solve this issue. You could for example apply a function to extract the variables' values after you generated the DataFrame like in your code:
df = pd.DataFrame.from_dict(x, orient='index').reset_index()
df.columns = ['Network', 'value']
df.value = df.value.apply(lambda x: x.X)I would set up the DataFrame like this to make it more concise and readable:
df = pd.DataFrame({'Network': (i,j), 'value': x[i,j].X} for (i,j) in x)
Both approaches result in the same DataFrame.
Cheers,
Matthias0 -
More on....Dictionary to DataFrame
0
Post is closed for comments.
Comments
3 comments