Skip to main content

Converting my gurobi dict to dataframe

Answered

Comments

2 comments

  • 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

Please sign in to leave a comment.