Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia DataFrames countmap()

Tags:

julia

Edit: countmap() is in StatsBase.jl and is working as expected. I'm not sure how to change this to an answered problem or if I should I delete it.

using DataFrames
using CSV

train = DataFrame(CSV.File("training.csv"))
countmap(train.column)



UndefVarError: countmap not defined

Stacktrace:
 [1] top-level scope
   @ In[40]:1
 [2] eval
   @ .\boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1094

I get that error running the code. Was countmap deprecated at some point and I just cannot find any updates about it or am I missing something?

like image 225
Josh Avatar asked Apr 17 '26 04:04

Josh


2 Answers

Are you looking for countmap from the StatsBase.jl package?

like image 124
Benoit Pasquier Avatar answered Apr 19 '26 17:04

Benoit Pasquier


You can use the following pattern to get a DataFrame instead of a Dict as a result:

combine(groupby(train, :column), nrow)

(in many cases it will be much faster than countmap)

Also instead of:

DataFrame(CSV.File("training.csv"))

it is more efficient to write:

CSV.read("training.csv", DataFrame)
like image 43
Bogumił Kamiński Avatar answered Apr 19 '26 16:04

Bogumił Kamiński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!