Skip to content

Support multi-column DataFrames in Initializer#3552

Merged
blnicho merged 1 commit intoPyomo:mainfrom
jsiirola:pandas-df-initializer
Apr 8, 2025
Merged

Support multi-column DataFrames in Initializer#3552
blnicho merged 1 commit intoPyomo:mainfrom
jsiirola:pandas-df-initializer

Conversation

@jsiirola
Copy link
Copy Markdown
Member

@jsiirola jsiirola commented Apr 8, 2025

Fixes # .

Summary/Motivation:

This relaxes the requirements in the DataFrameInitializer to accept multi-column DataFrame objects. This allows DataFrames to be used directly to initialize 2-dimensional objects where the second dimension are the column labels.

For example, the following will work:

from pyomo.environ import *
import pandas as pd

df = pd.read_csv('data.csv')

m = ConcreteModel()
m.R = Set(initialize=df.index)
m.C = Set(initialize=list(df))
m.data = Param(m.R, m.C, initialize=df)

Changes proposed in this PR:

  • Relax restriction on multi-column DataFrames (and add tests)

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@jsiirola jsiirola force-pushed the pandas-df-initializer branch from a65531d to da9befd Compare April 8, 2025 16:59
@blnicho blnicho merged commit 5e49df7 into Pyomo:main Apr 8, 2025
35 checks passed
@jsiirola jsiirola deleted the pandas-df-initializer branch April 8, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants