Temporal type conversion error reported when using DolphinDB Python API

29 Views Asked by At

I am trying to append data to a DolphinDB table using MultithreadTableWriter provided by DolphinDB Python API.

timestring=datetime.strptime(str(futures_[i].nActionDay)+""+str(futures_[i].nTime).zfill(9),'%Y%m%d%H%M%S%f')
writer.insert(futures_[i].szWindCode.decode('utf-8'), timestring,futures_[i].nMatch)

But an error message is reported: Data conversion error: unsupported type [<class ‘datetime.datetime'>].

Can anyone provide guidance on how to fix this issue? Thanks in advance.

1

There are 1 best solutions below

0
damie On BEST ANSWER

The error lies in that the DolphinDB Python API doesn’t support the datetime.datetime data type. You need to convert it to np.datetime64 using the function pd.to_datetime.

Refer to the following example:

data_path = "/path/20210901tick.csv"
df = pd.read_csv(data_path)
df["SecurityID"] = df["SecurityID"].astype('str')+".SH"
df["TradeTime"] = pd.to_datetime(df["TradeTime"], format='%Y.%m.%dT%H:%M:%S.%f')