Don’t call Dates.format on your column, because it converts Dates to String so in general it is a bad practice. Leave it as Date unless you want to present data.
…apologies but how does this work for a column of times i.e. converting a dataframe column typically “01:10:46” string to 01:10:46 Time. I blow up with either ‘no method matching’ or ‘no method matching Int64(::Vector{Any})’ etc etc. Dataframe column is loaded with 700 rows of Any.
The first thing to realise is that converting DataFrame columns is not different from converting regular Arrays of any type to any other type, as DataFrame columns are just vectors. So you really just need to know how to convert a String to a Time object, irrespective of where this String is stored.
The second thing to note is that getting a numerical value out of a string is generally referred to as “parsing”, rather than “conversion”. With this, you have:
julia> using Dates
julia> parse(Time, "01:10:46")
01:10:46
julia> typeof(ans)
Time
and then broadcast that over your data, i.e. parse.(Time, df.timecol) (although I can’t guarantee that all your strings have the right format to be parsed, so you might have to fiddle with it a bit!)
PS how did you end up with 700 columns of type Any? If you are using XLSX.jl to read an Excel file, consider the infer_eltypes = true kwarg.
thank you very much for the reply. I have a df column with 700 rows of string time in a df.Time column which has come from an xslx but I had missed the infer_eltypes option.
parse(Time, df.“Time”) gives methodError
I’m trying to re-write the entire df.Time column. In the xlsx file the times are in time format and add up.
new to Julia and coming from a Python background. Again thanks for the comment, I’ll keep at it.
You have already converted the df.Time column to a Time type. It is no longer a string, so parse doesn’t work. Try again on your “raw” data frame with string types.
Good spot the df.Time column got corrected with the great infer_eltype suggestion. Other similar columns in the df remained Any and a parse.(Time, df.“Avg Pace”) gives…
with the useful suggestion of infer_eltypes that worked on the first Time column leaving the remaining others.
Think I’ll take a few steps backwards. Didn’t want to take up too much of people’s time etc. From the comments I think its the raw data more than my logic which is a step. Thanks.