csv格式的tick行情数据导入分布式表时时间类型怎么转换
DolphinDB数据库建表建库代码如下:
dbDate = database("", VALUE, 2020.01.01..2020.12.31)
dbSymbol=database("", HASH, [SYMBOL, 10])
db = database("dfs://level2", COMPO, [dbDate, dbSymbol])
schemaTable=table(
array(SYMBOL,0) as symbol,
array(SYMBOL,0) as market,
array(DATE,0) as date,
array(TIME,0) as time,
array(DOUBLE,0) as preClose,
array(DOUBLE,0) as open,
array(DOUBLE,0) as high,
array(DOUBLE,0) as low,
array(DOUBLE,0) as last,
array(INT,0) as numTrades,
array(INT,0) as curNumTrades,
array(INT,0) as volume,
array(INT,0) as curVol,
array(DOUBLE,0) as turnover
)
db.createPartitionedTable(schemaTable,`quotes,`date`symbol)
csv文件样本数据如下:
python 代码如下:
import dolphindb as ddb
import numpy as np
import pandas as pd
csv_file="D:/data/stock/Level2text/20200602e.csv"
csv_data=pd.read_csv(csv_file,dtype={'symbol':str})
csv_df=pd.DataFrame(csv_data)
s = ddb.session()
s.connect("127.0.0.1", 8848,"admin","123456")
s.run("tableInsert{{loadTable('{db}', `{tb})}}".format(db="dfs://level2",tb="quotes"), csv_df)
运行时报错:
Traceback (most recent call last):
File "D:/data/import.py", line 40, in <module>
s.run("tableInsert{{loadTable('{db}', `{tb})}}".format(db="dfs://level2",tb="quotes"), csv_df)
File "C:\Users\tester\AppData\Local\Programs\Python\Python37\lib\site-packages\dolphindb\session.py", line 67, in run
return self.cpp.run(script, *args)
RuntimeError: <Server Exception> in call: The column [date] expects type of DATE, but the actual type is STRING.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个需要进行类型转换。比如可以在
read_csv()
方法中,通过parse_dates
参数直接将某些列转换成datetime64
类型: