Hey everyone,
I’d like to use scipy.optimize in Domo to perform optimization calculations (similar to Excel Solver).
Since MagicETL has a Python Tile, is this where I should implement it?
Thank you!
You can view a list of installed packages on the packages tab inside the python tile. If you do a search for scipy you should see it in the list.
Make sure scipy.optimize is installed. It should be pre-installed in the Domo Python environment.
import pandas as pd from scipy.optimize import minimize
The Python tile will use Pandas DataFrames. Something like this.
import pandas as pd from scipy.optimize import minimize # Assuming your input data looks something like this: # df = pd.DataFrame({ # 'variable': ['x1', 'x2'], # 'coefficient': [5, 8], # 'constraint': [20, 30] # }) # Input data from the Python Tile coefficients = df['coefficient'].values constraints = df['constraint'].values # Objective function to minimize def objective(x): return sum(coefficients * x) # Constraints: Example constraint that the sum of variables <= 100 constraint = {'type': 'ineq', 'fun': lambda x: 100 - sum(x)} # Bounds: Non-negative variables bounds = [(0, None)] * len(coefficients) # Initial guess for the variables x0 = [0] * len(coefficients) # Run the optimization result = minimize(objective, x0, bounds=bounds, constraints=[constraint]) # Output results df_output = pd.DataFrame({'variable': df['variable'], 'value': result.x})
Note - Domo also has Jupyter Workspace, where you can use Python code.