Suppose I have a Dataframe. One of the columns contains Dates sorted from low to high. Another columns contains integers. On particular dates, the value in the integer-column changes. What query will allow me to find see the dates on which the value in the integer-column has changed?
I want to say just use a for-loop but you can also do this I suppose
julia> df = DataFrame(dates=today()-Day(5):Day(1):today(), ints = [1,1,2,3,3,4])
6Ć2 DataFrame
Row ā dates ints
ā Date Int64
āāāāāā¼āāāāāāāāāāāāāāāāāāā
1 ā 2021-10-19 1
2 ā 2021-10-20 1
3 ā 2021-10-21 2
4 ā 2021-10-22 3
5 ā 2021-10-23 3
6 ā 2021-10-24 4
julia> df[[0;diff(df.ints)] .!= 0, :]
3Ć2 DataFrame
Row ā dates ints
ā Date Int64
āāāāāā¼āāāāāāāāāāāāāāāāāāā
1 ā 2021-10-21 2
2 ā 2021-10-22 3
3 ā 2021-10-24 4
4 Likes
If one also wants to keep the first date as a reference, an alternative:
df.dates[df.ints .!= circshift(df.ints,1)]
4-element Vector{Date}:
2021-10-19
2021-10-21
2021-10-22
2021-10-24