Formatting a date in a row column of a data frame

Is there a way to do something like this (it's in R)

df$dataCol <- as.Date(df$dataCol, format="%Y%m%d")

      

where dataCol has the format "20151009".

  • Is there a way to change the column type to date in julia?
  • I haven't found a way to do this with the Date.jl package.
+3


source to share


2 answers


There is a constructor Date

with an argument for the format, but the syntax is slightly different.



using Dates
Date( "20141123", DateFormat("yyyymmdd") )

      

+2


source


This is the best way to do the first part of my question



using Dates
dateReported = map((x) -> string(x), df[:DateReported])
df[:DateOccurred] = map((x) -> if match(r"^((19|20)\d\d)(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])", x)!=nothing Date(x, DateFormat("yyyymmdd")) end, dateOccurred)

      

0


source







All Articles