-1

The sample data from csv is shown as follows:

datetime symbol price volume
10/1/2020 9:00 XYZ 10.68 375
10/1/2020 9:00 XYZ 10.9 66
10/1/2020 9:00 XYZ 11.42 103
10/1/2020 9:00 XYZ 12.62 280
10/1/2020 9:00 XYZ 10.73 23
10/1/2020 9:00 XYZ 11.44 299

I executed the following line to read the data:

schemaTB = extractTextSchema(csvFile)
update schemaTB set type="DATETIME" where name="datetime"
schemaTB[`format]=["M-d-y h:m:s",,,];
t = loadText(csvFile,,schemaTB)

But it report an error:

t = loadText(csvFile, , schemaTB) => Invalid temporal format M-d-y h:m:s
dbaa9948
  • 189
  • 2
  • 10
  • You're specifying `M-d-y` but the date appears to be in `MM/DD/YYYY` format (or something like that). The separator, at least, is wrong. – SiHa Nov 25 '21 at 08:12

2 Answers2

0

I'm thinking of a couple of options here, perhaps opening it with pandas and parsing it to datetime and uploading the dataframe? Another option would be manipulating the text into the standard dolphinDB (which is different from pandas) please refer here 6.3.2 Data type conversion for more information about it

for example:

import dolphindb as ddb
import pandas as pd
s = ddb.session()
s.connect(host, port, "admin", "123456")
t = pd.read_csv('path_to_csv_file')
t['datetime'] = pd.to_datetime(t['datetime'],infer_datetime_format=True)
s.upload({'t':t})
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
0

The revised code would look like this

schemaTB = extractTextSchema(csvFile)
update schemaTB set type="DATETIME" where name="datetime"
schemaTB[`format]=["MM/dd/yyyy HH:mm",,,];
t = loadText(csvFile,,schemaTB)

For more information, please refer to section 2 and 4 in import_csv tutorial

jinwandalaohu
  • 226
  • 1
  • 7