jkrumbiegel / DataFrameMacros.jl

Macros that simplify working with DataFrames.jl
MIT License
61 stars 4 forks source link

Unexpected behavior with nrow to count instances in grouped data #9

Closed milanhej closed 1 year ago

milanhej commented 2 years ago

Here is an odd result I obtained (Julia 1.6.1)

using DataFrames, DataFrameMacros, Chain, CSV
iris = CSV.read("iris.csv", DataFrame);
g = groupby(iris, "Species");
combine(g, nrow)

3×2 DataFrame
 Row │ Species          nrow  
     │ String           Int64 
─────┼────────────────────────
   1 │ Iris-setosa         50
   2 │ Iris-versicolor     50
   3 │ Iris-virginica      50

@chain iris begin
       @groupby(:Species)
       @combine(:count = nrow)
       end

Row │ Species          count  
     │ String           #nrow… 
─────┼─────────────────────────
   1 │ Iris-setosa      nrow
   2 │ Iris-versicolor  nrow
   3 │ Iris-virginica   nrow

Is there a separate function using DataFrameMacros to obtain counts of group instances?

Thanks.

jkrumbiegel commented 1 year ago

this now exists as @combine(..., @nrow) so it doesn't interfere with other syntax https://github.com/jkrumbiegel/DataFrameMacros.jl/pull/25