Hi! I’m reading csv file and puttining it into DataFrames. I can’t cope with changing the time column from “2019-11-18T13:09:31Z” format to “2019-11-18”. Can someone help me ?
I have code
cap_file = readlines(datadir('query.csv'))
df = DataFrame(data(cap_file[end]))
df = @transform(df, time = string.(chop.(:time)))
@transform(df, time = Date.(:time))
but it gives me “syntax: character literal contains multiple characters”
This should help
julia> s = "2019-11-18T13:09:31Z"
julia> parsed_datetime = DateTime(s, dateformat"y-m-dTH:M:SZ")
julia> d = Date(parsed_datetime)
You could do that as well. But sub-setting a string like that can make code less readable and more fragile.
Sorry, but I still have problem. How to do it on one of the columns of a table from DataFrames, where we have thousands of such dates?
Are the dates all in the same format?
Great, then you can just do something like
@transform(time = Date.(DateTime.(:time, dateformat"y-m-dTH:M:SZ")))
A great alternative is
CSV.File. It can parse the timestamps for you.
D = DataFrame!(CSV.File(raw"C:\Data.csv",
datarow=3, # Data starts on the third row