英文:
Error reported when using sma in a SQL query: X must be a numeric vector
问题
以下是您的脚本:
def ma_process(data_table):
cols = open 'high' 'low' 'close' 'volume' 'amount' 'vwap'
base_table = select trade date, symbol from data_table
for col in cols:
print(col)
data = select trade_date, symbol, sma(col, 5) as aaa from data_table
base_table = lj(base, table, data, trade date 'symbol')
stock_db = database('dfs://stock db')
data_table = stock_db.loadTable('stock daily_hfq')
ma_process(data_table)
错误消息报告了X必须是数值向量
。是否有人可以帮助我确定此问题的原因并修改我的脚本?
英文:
Here is my script:
def ma process(data table){
  cols = open'high'low'close' volume'amount'vwap
base_table = select trade date, symbol from data_table
for(col in cols){
     print(col)
data = select trade_date, symbol, sma(col,5) as aaa from data_table
base table = lj(base,table,data,trade date'symbol)
}
}
stock_db = database('dfs://stock db')
data_table = stock_db.loadTable('stock daily_hfq')
ma_process(data table)
An error message was reported: X must be a numeric vector
. Can anyone help me identify the cause of this issue and modify my script?
答案1
得分: 1
cols
是一个字符串,不能直接在 SQL 查询中用作列引用。要根据给定的列名查询列,请使用元编程:
col="xxx"
sql(select=[sqlCol("trade_date"), sqlCol("symbol"), sqlColAlias(makeUnifiedCall(sma, [sqlCol(col), 5]), 'aaa')], from="data_table")
英文:
cols
is a string and cannot be directly used in the SQL query as a column reference. To query a column based on the given column name, use metaprogramming:
col="xxx"
sql(select=[sqlCol("trade_date"),sqlCol("symbol"), sqlColAlias(makeUnifiedCall(sma, [sqlCol(col), 5]), `aaa) ], from="data_table" )
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论