Skip to main content

Converting my gurobi dict to dataframe

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    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?.
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    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,
    Matthias

    0
  • ric slator
    Gurobi-versary
    First Comment

    More on....Dictionary to DataFrame

    0

Post is closed for comments.