0
我有一套使用Python創建的4個腳本。他們從Excel工作簿中獲取數據並繪製在3軸圖上。然後他們計算每個數據集的迴歸曲線(曲面)。我想要創建一個表格,將其寫回到同一個Excel工作簿中的新工作表中。該表格將顯示迴歸分析計算出的參數。表格佈局是:創建和填充數據表
Model Parameter A Parameter B
Sulphide
Mixed
Oxide
Leach
我是一個地質學家,而不是一個程序員,我也很新到Python。所以,如果可以的話,請爲我貶低它。我已經在下面複製了部分腳本,希望它有所幫助。
'''
==============================================================================
======================== Sulphide Model Fitting ==============================
'''
#TCu_col = 0 # Variable currently unused
ASCu_col = 1 # Variable that will determine the modeled data
AICu_col = 2 # Variable that will determine the modeled data
res_col = 3 # Recovery on "Y" Axis
ASCu = sulphideData[:,ASCu_col]
AICu = sulphideData[:,AICu_col]
res = sulphideData[:,res_col]
def residual(params, x1, x2, res_col):
a = params['a'].value
b = params['b'].value
#=============================================================================
model = ((a*(ASCu/(ASCu + AICu))) + (b*(AICu/(ASCu + AICu))))
#=============================================================================
return (res-model)
params = Parameters()
params.add('a', value=1)
params.add('b', value=1)
out = minimize(residual, params, args=(ASCu_col, AICu_col, res_col))
a = np.round(params['a'].value) # This is parameter 'a' i want reported in the excel table
b = np.round(params['b'].value) # This is parameter 'b' i want reported in the excel table
print(a,b)
x1 = np.linspace(min(sulphideData[:,ASCu_col]),max(sulphideData[:,ASCu_col]),100)
x2 = np.linspace(min(sulphideData[:,AICu_col]),max(sulphideData[:,AICu_col]),100)
X = x1
Y = x2
X,Y = np.meshgrid(X,Y)
我使用xlrd函數:book = xlrd.open_workbook('data.xlxs') – user3355594
感謝您的鏈接。我並不指望任何人只需指出正確的命令以及如何使用/理解它們就可以完成這項工作。再次感謝。 – user3355594