这段代码将一个 excel 文件作为输入,其中有几列在一列中具有相同的值,这导致错误 ang 给出了错误的输出。此代码在 jupyter notebook 中有效,但在 python 文件中失败
`@app.route('/gct',methods=['POST','GET'])
def gct():
df = pd.read_excel('data.xlsx')
# assigned the integer 15 to the variable 'nobs'
nobs = -15
#df = df.loc[:, df.apply(pd.Series.nunique) == 1]
#df = df.iloc[:,0].values
# assigning the last 15 observations to the variable 'X_test', while the rest will be assigned to the variable 'X_train'
X_train, X_test = df[0:-nobs], df[-nobs:]
#X_train.columns = X_train.columns.str.strip()
result = granger.granger_causation_matrix(X_train, variables=X_train.columns)
print("gct")
return render_template("gct.html",output=X_train)
I tried X_train.columns = X_train.columns.str.strip()`
DataFrame 中的一个或多个列仅包含一个值,测试不支持这一点。尝试删除只有一个值的列。要查找列,请尝试:
for k,v in df.nunique().items():
if v == 1:
print(k,v)