1

I have the next format for my date in my dataframe:

Typeof(DateTime("2021-12-17T06:00:00"))
Feather.Arrow.Timestamp{Microsecond}

I want to filter the data by date, but I can't because of the type. I tried to chop it, but again because of the type I couldn't.

MethodError: no method matching chop(::Feather.Arrow.Timestamp{Microsecond}; head=10, tail=2)
Closest candidates are:
  chop(::AbstractString; head, tail) at strings/util.jl:184

So I tried to change the type using parse but it is not allowed. In R, I use filter and face no problem. What can I do?

Jafar Isbarov
  • 1,363
  • 1
  • 8
  • 26
  • Please edit your question when you want to clarify or add things, don't put it into an "answer". – Andre Wildberg Jan 03 '22 at 20:28
  • How did you create the data frame? What external packages may have been used? – Andre Wildberg Jan 03 '22 at 20:30
  • Agreed with @AndreWildberg . It's difficult and pointless to try to solve this further without a [Minimal working example](https://en.wikipedia.org/wiki/Minimal_working_example) code. – Sundar R Jan 03 '22 at 21:07

1 Answers1

0

To filter a DataFrame's row by value, see the Subsetting section of the DataFrames manual.

julia> df = DataFrame(n = 1:16, dates = DateTime("2021-12-17T06:00:00"):Day(1):DateTime("2022-01-01T06:00:00"));

julia> summary(df)
"16×2 DataFrame"

julia> df[DateTime("2021-12-25") .<= df.dates .<= DateTime("2021-12-31"), :]
6×2 DataFrame
 Row │ n      dates               
     │ Int64  DateTime            
─────┼────────────────────────────
   1 │     9  2021-12-25T06:00:00
   2 │    10  2021-12-26T06:00:00
   3 │    11  2021-12-27T06:00:00
   4 │    12  2021-12-28T06:00:00
   5 │    13  2021-12-29T06:00:00
   6 │    14  2021-12-30T06:00:00

julia> #OR:

julia> datefilter(dates) = DateTime("2021-12-25") .<= dates .<= DateTime("2021-12-31")
datefilter (generic function with 1 method)

julia> subset(df, :dates => datefilter)
6×2 DataFrame
 Row │ n      dates               
     │ Int64  DateTime            
─────┼────────────────────────────
   1 │     9  2021-12-25T06:00:00
   2 │    10  2021-12-26T06:00:00
   3 │    11  2021-12-27T06:00:00
   4 │    12  2021-12-28T06:00:00
   5 │    13  2021-12-29T06:00:00
   6 │    14  2021-12-30T06:00:00

For the specifics of what you want to accomplish here, it's most useful if you can show us the actual code you've tried and what its intended purpose is. (chop in Julia is used to process strings. tidyr-type chop may be replaced by groupbys instead, but that again depends on what your end goal here is.)

Sundar R
  • 13,776
  • 6
  • 49
  • 76