我正在做一个时间序列问题。当我在做 AR 模型时,一切正常。
# Import the module for estimating an ARMA model
from statsmodels.tsa.arima_model import ARMA
# Fit the data to an AR(p) for p = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for p in range(7):
mod = ARMA(data, order=(p,0))
res = mod.fit()
# Save BIC for AR(p)
BIC[p] = res.bic
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of AR Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是,当我在做 MA 模型时:
# Fit the …Run Code Online (Sandbox Code Playgroud) 我正在使用 statsmodel 中的 OLS,链接是https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html
#USD
X = sm.add_constant(USD)
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())
OLS Regression Results
========================================================================================
Dep. Variable: All Ordinaries closing price R-squared: 0.265
Model: OLS Adj. R-squared: 0.265
Method: Least Squares F-statistic: 352.4
Date: Tue, 23 Oct 2018 Prob (F-statistic): 2.35e-67
Time: 17:30:24 Log-Likelihood: -8018.8
No. Observations: 977 AIC: 1.604e+04
Df Residuals: 975 BIC: 1.605e+04
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 1843.1414 149.675 12.314 …Run Code Online (Sandbox Code Playgroud) 据我所知,Xlsxwriter 可能是使用千位分隔符格式化数字的最佳软件包。我已经阅读了很多次 xlsxwriter 文档,仍然很困惑,我认为其他人可能也有同样的问题,因此我在这里发布我的问题。我有一个 pandas 数据框 DF_T_1_EQUITY_CHANGE_Summary_ADE,我想将它们导出到 Excel 并使用格式化千位分隔符。
Row Labels object
Sum of EQUITY_CHANGE float64
Sum of TRUE_PROFIT float64
Sum of total_cost float64
Sum of FOREX VOL float64
Sum of BULLION VOL float64
Oil float64
Sum of CFD VOL object
Sum of BITCOIN VOL object
Sum of DEPOSIT float64
Sum of WITHDRAW float64
Sum of IN/OUT float64
dtype: object
Run Code Online (Sandbox Code Playgroud)
数据帧 DF_T_1_EQUITY_CHANGE_Summary_ADE 是明确的,除了第一列行标签是对象,其他都是数字。因此,我使用 xlsxwriter 将数据框写入 Excel:
import xlsxwriter
num_fmt = workbook.add_format({'num_format': '#,###'}) #set the separator I want
writer = pd.ExcelWriter('ADE_CN.xlsx', …Run Code Online (Sandbox Code Playgroud)