A little problem with combine from DataFrames.jl

Hi! I am learning the usage of DataFrames.jl from Julia Academy and I found a problem.
When I used combine for creating a new column, the tutorial and any other material (like this) that I have consulted says the following:

origin_brand2 = @pipe df |>
                      groupby(_, [:origin, :brand]) |>
                      combine(_, nrow) 

origin_brand2 has to have a column called β€œnrow”; however, I obtained a x1 column.


So, Did I do something wrong? or maybe is required to do an additional step changing the name?
Regards

1 Like

Thanks for this, OP. Glad you are working with DataFrames.

This is indeed a weird bug. However I can’t seem to replicate.

julia> using Pipe, DataFrames

julia> df = DataFrame(a = [1, 1, 2, 2], b = rand(4));

julia> @pipe df |>
       groupby(_, :a) |>
       combine(_, nrow)
2Γ—2 DataFrame
β”‚ Row β”‚ a     β”‚ nrow  β”‚
β”‚     β”‚ Int64 β”‚ Int64 β”‚
β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1   β”‚ 1     β”‚ 2     β”‚
β”‚ 2   β”‚ 2     β”‚ 2     β”‚

It seems like you are on the latest version of DataFrames, though, so I don’t have a great answer.

Sorry this isn’t working how you expect. In the meantime you can do

julia> @pipe df |>
       groupby(_, :a) |>
       combine(_, :a => length => :nrow)
2Γ—2 DataFrame
β”‚ Row β”‚ a     β”‚ nrow  β”‚
β”‚     β”‚ Int64 β”‚ Int64 β”‚
β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1   β”‚ 1     β”‚ 2     β”‚
β”‚ 2   β”‚ 2     β”‚ 2     β”‚
1 Like

Thanks for your answer. I am continuing with the course. As an R native, I like Julia and this package especially for the similarity to tidyverse. This bug doesn’t affect my motivation to learn more about it. Thanks rather for the alternative to change names.
Regards