Comparing times in a dataframe

Dear all,
I am not very comfortable with time formats. I have the following dataframe.

┌─────────┬──────────┐
│ id_site │     hour │
│ String7 │     Time │
├─────────┼──────────┤
│    BAN4 │ 08:48:00 │
│    BAN4 │ 08:56:00 │
│    BAN4 │ 09:01:00 │
│    BAN4 │ 09:37:00 │
│    BAN4 │ 09:49:00 │
│    BAN4 │ 10:02:00 │
│    BAN4 │ 10:05:00 │
│    BAN4 │ 10:40:00 │
│    BAN4 │ 12:05:00 │
│    BAN5 │ 08:41:00 │
└─────────┴──────────┘

How can I filter the lines to keep only those for hour greater that 09:30 for example?

df[df.hour .> Time(9, 30), :]
2 Likes

Btw for straightforward questions like that AI works pretty well. Here’s what I got from JuliaHub’s AI assistant:

To filter the lines in your DataFrame to keep only those with an hour greater than 09:30, you can use the following code snippet in Julia:

using DataFrames

# Sample DataFrame
df = DataFrame(id_site = ["BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN5"],
               hour = [Time("08:48:00"), Time("08:56:00"), Time("09:01:00"), Time("09:37:00"), Time("09:49:00"),
                       Time("10:02:00"), Time("10:05:00"), Time("10:40:00"), Time("12:05:00"), Time("08:41:00")])

# Filter the DataFrame to keep only rows with hour greater than 09:30
filtered_df = filter(row -> row.hour > Time("09:30:00"), df)

FWIW using filter I would write this as:

filter(:hour => >(Time(9, 30)), df)