Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i read a csv file with time in AM and PM in julia

Tags:

julia

I am using Julia CSV and I am trying to read data with DateTime in the form 10/17/2012 12:00:00 AM i tried

dfmt = dateformat"mm/dd/yyyy HH:MM:SS"
data =CSV.File("./Fremont_Bridge_Bicycle_Counter.csv", dateformat=dfmt) |> DataFrame
println(first(data,8))

but the thing is that I think the AM and PM makes the string not recognized as a date can someone help show how to pass this as a date

like image 223
kim Avatar asked Mar 03 '23 14:03

kim


1 Answers

You can use the p specifier, which matches AM or PM. With that, your date format would look like this:

dfmt = dateformat"mm/dd/yyyy HH:MM:SS p"

You can see that the parsing is correct:

julia> DateTime("10/17/2012 12:00:00 AM", dfmt)
2012-10-17T00:00:00

To see all the possible format characters, check out the docstring of Dates.DateFormat, which is accessible in the REPL through ?DateFormat.

like image 197
Anshul Singhvi Avatar answered Mar 15 '23 08:03

Anshul Singhvi