|
@@ -399,20 +399,20 @@ func ParseStlExcel(excelPath string) (TrendChart, SeasonalChart, ResidualChart C
|
|
|
|
|
|
func execStlPythonCode(path, toPath string, period, seasonal, trend, trendDeg, seasonalDeg, lowPassDeg int, fraction float64, robust bool) (err error) {
|
|
func execStlPythonCode(path, toPath string, period, seasonal, trend, trendDeg, seasonalDeg, lowPassDeg int, fraction float64, robust bool) (err error) {
|
|
pythonCode := `
|
|
pythonCode := `
|
|
|
|
+import json
|
|
|
|
+import warnings
|
|
|
|
+warnings.filterwarnings('ignore')
|
|
import pandas as pd
|
|
import pandas as pd
|
|
from statsmodels.tsa.seasonal import STL
|
|
from statsmodels.tsa.seasonal import STL
|
|
from statsmodels.nonparametric.smoothers_lowess import lowess
|
|
from statsmodels.nonparametric.smoothers_lowess import lowess
|
|
from statsmodels.tsa.stattools import adfuller
|
|
from statsmodels.tsa.stattools import adfuller
|
|
from statsmodels.stats.diagnostic import acorr_ljungbox
|
|
from statsmodels.stats.diagnostic import acorr_ljungbox
|
|
import numpy as np
|
|
import numpy as np
|
|
-import json
|
|
|
|
-import warnings
|
|
|
|
-warnings.filterwarnings('ignore')
|
|
|
|
|
|
|
|
file_path = r"%s"
|
|
file_path = r"%s"
|
|
-df = pd.read_excel(file_path, parse_dates=['日期'])
|
|
|
|
|
|
+df = pd.read_excel(file_path, parse_dates=['日期'], engine='openpyxl')
|
|
df.set_index('日期', inplace=True)
|
|
df.set_index('日期', inplace=True)
|
|
-
|
|
|
|
|
|
+df = df[df.index.notna()]
|
|
|
|
|
|
period = %d
|
|
period = %d
|
|
seasonal = %d
|
|
seasonal = %d
|
|
@@ -439,7 +439,7 @@ stl = STL(
|
|
)
|
|
)
|
|
result = stl.fit()
|
|
result = stl.fit()
|
|
|
|
|
|
-smoothed = lowess(df['值'], df.index, frac=fraction)
|
|
|
|
|
|
+smoothed = lowess(df['值'], np.arange(len(df)), frac=fraction)
|
|
|
|
|
|
trend_lowess = smoothed[:, 1]
|
|
trend_lowess = smoothed[:, 1]
|
|
|
|
|