I need to solve a large system of linear equations using a least squares method. So far I have found the answers whilst unconstrained but would like to limit my answers to be non-negative. The code I have been using is shown below. 'Sheet 1' holds a matrix of size 30x135 and 'sheet 2' a matrix of size 30x1.
import pandas as pd
import numpy as np
df = pd.read_excel("C:\\example\price_analysis.xlsx", sheet_name = "Sheet1")
print(df)
dg = pd.read_excel("C:\\example\price_analysis.xlsx", sheet_name = "Sheet2")
print(dg)
z = np.linalg.lstsq(df,dg, rcond=None)
print(z)
I tried using the answer from this post but couldn't work out how to find the least squares result where all values are positive, rather than simply changing all negative values to be 0.