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.

回答

这个需要进行类型转换。比如可以在 read_csv() 方法中,通过 parse_dates 参数直接将某些列转换成 datetime64 类型:

csv_data=pd.read_csv(csv_file,dtype={'symbol':str},parse_dates=['date','time'])

以上是 csv格式的tick行情数据导入分布式表时时间类型怎么转换 的全部内容, 来源链接: utcz.com/a/42884.html

回到顶部