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.