&引用;ArgumentError:时间戳必须是严格单调的;在Julia时间数组构造函数中

&引用;ArgumentError:时间戳必须是严格单调的;在Julia时间数组构造函数中,julia,Julia,我想找出导致此错误的重复数据的位置,但如何确定 using DataFrames, TimeSeries, CSV s = "2019-12-25,3 2020-01-01,6 2019-12-25,9 2020-01-02,10 2020-01-03,11 2020-01-04,12 2020-01-02,13 2020-01-02,14" df=CSV.read(IOBuffer(s), typ

我想找出导致此错误的重复数据的位置,但如何确定

using DataFrames, TimeSeries, CSV
s = "2019-12-25,3
       2020-01-01,6
       2019-12-25,9
       2020-01-02,10
       2020-01-03,11
       2020-01-04,12
       2020-01-02,13
       2020-01-02,14"
df=CSV.read(IOBuffer(s), types=[Date,Int], header=["timestamp","V")
ta = TimeArray(df, timestamp=:timestamp)
错误消息

ERROR: ArgumentError: timestamps must be strictly monotonic
Stacktrace:
 [1] (::TimeSeries.var"#_#1#2")(::Bool, ::Type{TimeArray{Int64,1,Date,Array{Int64,1}}}, ::Array{Date,1}, ::Array{Int64,1}, ::Array{Symbol,1}, ::DataFrame) at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/timearray.jl:81
 [2] TimeArray at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/timearray.jl:65 [inlined]
 [3] #TimeArray#3 at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/timearray.jl:89 [inlined]
 [4] TimeArray(::Array{Date,1}, ::Array{Int64,1}, ::Array{Symbol,1}, ::DataFrame) at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/timearray.jl:89
 [5] #TimeArray#3(::Symbol, ::Type{TimeArray}, ::DataFrame) at /home/dlin/.julia/packages/TimeSeries/8Z5Is/src/tables.jl:70
 [6] (::Core.var"#kw#Type")(::NamedTuple{(:timestamp,),Tuple{Symbol}}, ::Type{TimeArray}, ::DataFrame) at ./none:0
 [7] top-level scope at REPL[239]:1
我想找出导致错误的索引,可能类似于

│ Row │ timestamp  │ V     │
│     │ Date       │ Int64 │
├─────┼────────────┼───────┤
│ 1   │ 2019-12-25 │ 3     │
│ 3   │ 2019-12-25 │ 9     │
或者最好找出所有非唯一值行

│ Row │ timestamp  │ V     │
│     │ Date       │ Int64 │
├─────┼────────────┼───────┤
│ 1   │ 2019-12-25 │ 3     │
│ 3   │ 2019-12-25 │ 9     │
│ 4   │ 2020-01-02 │ 10    │
│ 7   │ 2020-01-02 │ 13    │
│ 8   │ 2020-01-02 │ 14    │

删除重复项,然后将
数据帧
传递到
时间数组

julia> TimeArray(aggregate(df, :timestamp, minimum, sort=true), timestamp=:timestamp)
2×1 TimeArray{Int64,1,Date,Array{Int64,1}} 2019-12-25 to 2020-01-01
│            │ V_minimum │
├────────────┼───────────┤
│ 2019-12-25 │ 3         │
│ 2020-01-01 │ 6         │
如果您有一个
DataFrame
并且只想识别重复的日期值,请使用
ununique
功能

julia> nonunique(df,:timestamp)
3-element Array{Bool,1}:
 0
 0
 1
如果只需要日期唯一的行:

julia> unique(df,:timestamp)
2×2 DataFrame
│ Row │ timestamp  │ V     │
│     │ Date       │ Int64 │
├─────┼────────────┼───────┤
│ 1   │ 2019-12-25 │ 3     │
│ 2   │ 2020-01-01 │ 6     │

通过@Przemyslaw Szufel的回答,我找到了查找内容的方法,但它仍然不完美,它不能显示原始行索引,只能显示第一个非唯一的内容

julia> v=nonunique(df,1)
8-element Array{Bool,1}:
 0
 0
 1
 0
 0
 0
 1
 1

julia> f=findfirst(v)
3
julia> df[df.Column1 .== df.Column1[f],:]
2×2 DataFrame
│ Row │ Column1    │ Column2 │
│     │ Date       │ Int64   │
├─────┼────────────┼─────────┤
│ 1   │ 2019-12-25 │ 3       │
│ 2   │ 2019-12-25 │ 9       │

顺便说一句,我发现“ArgumentError:时间戳必须是严格单调的”消息不仅是单调的,而且在检查timearray.jl的源代码后也是“排序的”。

你的标题提到了一个带有单调性错误的TimeSeries,而你的帖子提到了一个带有关键字错误的timearray。你能编辑你的帖子来澄清一下吗?我想我的数据已经被unique加入了,我想调试重复数据的位置,而不是把错误的输入数据放在哪里。虽然结果是0,0,1,我不知道数据是什么,`df[ununique(df,:timestamp),:]`我知道它是'2019-12-25',但它只是列出一行而不是所有的行。
df[.!ununique(df,:timestamp),:]
或更简单使用
unique
函数-查看我对答案的编辑我想找到重复的数据,它们来自两个独立的数据源,我需要找出哪一个是正确的,就像我的问题预期的输出一样。