Create a new DateTime dataframe column from Date and Time columns

Hi,

(sorry for the pedantic syntax…)

using DataFrames
using Dates

df = DataFrame(DATE=[Date("2025-01-01","yyyy-mm-dd"), Date("2025-01-01","yyyy-mm-dd"), Date("2025-01-02","yyyy-mm-dd")], TIME=[Time("00:00:00"), Time("12:00:00"), Time("00:00:00")])

gives

3×2 DataFrame
 Row │ DATE        TIME     
     │ Date        Time     
─────┼──────────────────────
   1 │ 2025-01-01  00:00:00
   2 │ 2025-01-01  12:00:00
   3 │ 2025-01-02  00:00:00

So I would like to create a third column with the full datetime stamp.
(In general) I struggle with the online creation of a dataframe column…
Any help welcome.

You mean like this?

julia> df = DataFrame(DATE = [Date(2025), Date(2025), Date(2025, 1, 2)], TIME = [Time(0), Time(12), Time(0)])
3×2 DataFrame
 Row │ DATE        TIME
     │ Date        Time
─────┼──────────────────────
   1 │ 2025-01-01  00:00:00
   2 │ 2025-01-01  12:00:00
   3 │ 2025-01-02  00:00:00

julia> df.dt = DateTime.(df.DATE, df.TIME); df
3×3 DataFrame
 Row │ DATE        TIME      dt
     │ Date        Time      DateTime
─────┼───────────────────────────────────────────
   1 │ 2025-01-01  00:00:00  2025-01-01T00:00:00
   2 │ 2025-01-01  12:00:00  2025-01-01T12:00:00
   3 │ 2025-01-02  00:00:00  2025-01-02T00:00:00

(first line just included to suggest an easier way to construct Dates/Times)

1 Like

Incredibly simple !
Thanks a lot !

1 Like