Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading date in csv as string instead of datetime #430

Closed
iserranoe opened this issue Mar 28, 2022 · 2 comments
Closed

Reading date in csv as string instead of datetime #430

iserranoe opened this issue Mar 28, 2022 · 2 comments

Comments

@iserranoe
Copy link

iserranoe commented Mar 28, 2022

I'm reading a csv file into a data frame. One of the columns is a date and Danfo is automatically reading and transforming it into datetime format; however I'd like to mantain the date as a string, how can I do it?

@risenW
Copy link
Member

risenW commented Apr 2, 2022

Hello @iserranoe Danfojs does not automatically parse dates. It only tries to parse date strings when you call the .dt method on the column. See https://danfo.jsdata.org/api-reference/general-functions/danfo.dt

@risenW risenW closed this as completed Apr 2, 2022
@iserranoe
Copy link
Author

iserranoe commented Jun 28, 2022

Hi @risenW, I've just came back to this problem. Let me show you more information, as I find Danfojs is parsing dates somehow.

I have a .csv file with this data:

,result,table,_measurement,_time,days,pH,total_hours
,_result,0,57b6,2022-06-27T14:39:55Z,0.003,14,0.076
,_result,0,57b6,2022-06-27T14:45:07Z,0.006,14,0.163
,_result,0,57b6,2022-06-27T14:50:19Z,0.010,14,0.249
,_result,0,57b6,2022-06-27T14:55:31Z,0.014,14,0.336
,_result,0,57b6,2022-06-27T15:00:43Z,0.017,14,0.423

I then read the csv file with dfd.readCSV and can see the dates are transformed:

>const dfd = require("danfojs-node")
>dfd.readCSV('./data.csv').then(df=>{df.print(); df.column('_time').print()}).catch(e=>{console.log(e)})

The output is:

 >dfd.readCSV('./data.csv').then(df=>{df.print(); df.ctypes.print(); df.column('_time').print()}).catch(e=>{console.log(e)})
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 1036,
  [Symbol(trigger_async_id_symbol)]: 1035,
  [Symbol(destroyed)]: { destroyed: false }
}
> ╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │                   │ result            │ table             │ _measurement      │ _time             │ days              │ pH                │ total_hours       ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ null              │ _result           │ 0                 │ 57b6              │ Mon Jun 27 2022…  │ 0.003             │ 14                │ 0.076             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ null              │ _result           │ 0                 │ 57b6              │ Mon Jun 27 2022…  │ 0.006             │ 14                │ 0.163             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ null              │ _result           │ 0                 │ 57b6              │ Mon Jun 27 2022…  │ 0.01              │ 14                │ 0.249             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ null              │ _result           │ 0                 │ 57b6              │ Mon Jun 27 2022…  │ 0.014             │ 14                │ 0.336             ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4          │ null              │ _result           │ 0                 │ 57b6              │ Mon Jun 27 2022…  │ 0.017             │ 14                │ 0.423             ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔══════════════╤═════════╗
║              │ float32 ║
╟──────────────┼─────────╢
║ result       │ string  ║
╟──────────────┼─────────╢
║ table        │ int32   ║
╟──────────────┼─────────╢
║ _measurement │ string  ║
╟──────────────┼─────────╢
║ _time        │ int32   ║
╟──────────────┼─────────╢
║ days         │ float32 ║
╟──────────────┼─────────╢
║ pH           │ int32   ║
╟──────────────┼─────────╢
║ total_hours  │ float32 ║
╚══════════════╧═════════╝

Error: File format not supported!
    at Series.NDframe (/home/ines/ofelia/frontend/node_modules/danfojs-node/dist/danfojs-base/core/generic.js:97:23)
    at new Series (/home/ines/ofelia/frontend/node_modules/danfojs-node/dist/danfojs-base/core/series.js:134:28)
    at DataFrame.$getColumnData (/home/ines/ofelia/frontend/node_modules/danfojs-node/dist/danfojs-base/core/frame.js:196:24)
    at DataFrame.column (/home/ines/ofelia/frontend/node_modules/danfojs-node/dist/danfojs-base/core/frame.js:1939:21)
    at REPL90:1:52
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

So, the dates are transformed from 2022-06-27T14:39:55Z format to Mon Jun 27 2022… format and I can't access the column dt.column('_time'). I'd like them to keep the original format, i.e. 2022-06-27T14:39:55Z, as a string instead of converting to datetime format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants