如何在python中实现"Range(" AC2:AC51 ").DataSeries Rowcol:=xlColumns, _ Type:=xlLinear, Date:=xlDay, Trend:



我有一个旧的Excel文档,里面有一些VBA代码,我真的不确定它在做什么。Sheets("1").Range("AC2:AC51").DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, Trend:=True

我想在python中实现这一点,以了解到底发生了什么。有什么提示吗?

我找到了Range.DataSeries方法,但没有任何解释。

更新:
我对VBA脚本有点恼火,忘记写我已经做过的事情。我使用以下输入值运行了脚本:
12.04、12.04、12.041、12.041,12.045,12.046,12.046、12.047、12.046和12.046

得到以下结果:
12.0407、12.0408、12.0409、12.0411、12.0412、12.0413、12.0414、12.0416、12.0417、12.0418、12.0420、12.0421、12.0422、12.0424、12.0425、12.0426、12.0427、12.0429、12.0430、12.0431、12.0433、12.0434、12.0435、12.0437、12.0438、12.0439、12.0441、12.0442、12.0443、12.0444、12.0446、12.0447、12.0448、12.0450、12.0451、12.0452、12.0454、12.0455、12.0456、12.0458、12.0459,12.0460、12.0461、12.0463、12.0464、12.0465、12.0467、12.0468、12.0469、12.0471

我自己发现了。

import numpy as np
import scipy as sp
import scipy.stats
import matplotlib as mpl
import matplotlib.pyplot as plt
data = [12.04, 12.04, 12.04, 12.041, 12.041, 12.041, 12.041, 12.041, 12.042, 12.042, 12.042, 12.042, 12.042, 12.043, 12.042, 12.043, 12.043, 12.043, 12.043, 12.044, 12.043, 12.044, 12.044, 12.044, 12.045, 12.044, 12.045, 12.045, 12.044, 12.044, 12.044, 12.045, 12.045, 12.046, 12.045, 12.046, 12.046, 12.046, 12.046, 12.046, 12.046, 12.046, 12.046, 12.046, 12.045, 12.046, 12.046, 12.047, 12.046, 12.046]
vba_result = [12.0407, 12.0408, 12.0409, 12.0411, 12.0412, 12.0413, 12.0414, 12.0416, 12.0417, 12.0418, 12.0420, 12.0421, 12.0422, 12.0424, 12.0425, 12.0426, 12.0427, 12.0429, 12.0430, 12.0431, 12.0433, 12.0434, 12.0435, 12.0437, 12.0438, 12.0439, 12.0441, 12.0442, 12.0443, 12.0444, 12.0446, 12.0447, 12.0448, 12.0450, 12.0451, 12.0452, 12.0454, 12.0455, 12.0456, 12.0458, 12.0459, 12.0460, 12.0461, 12.0463, 12.0464, 12.0465, 12.0467, 12.0468, 12.0469, 12.0471]
# generate numbers from 1 to 50
n = np.linspace(1, 50, 50)
# calculate the linear regression
lr = sp.stats.linregress(n, data)
# calculate the fitted lines values
s = [*map(lambda x: round(lr.slope * x + lr.intercept, 4), n)]
vba_result == s
# visualise the data
plt.subplots(dpi=300)
plt.plot(n, data, '.', label='data')
plt.plot(n, lr.intercept + lr.slope * n, label='fitted line')
plt.legend()
plt.show()

最新更新