# Does Julia have equivalent of Python: DF.column.map( dict )

**URL:** <https://discourse.julialang.org/t/does-julia-have-equivalent-of-python-df-column-map-dict/47048>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 22, 2020, 6:08am UTC](https://discourse.julialang.org/t/does-julia-have-equivalent-of-python-df-column-map-dict/47048 "2020-09-22T06:08:54Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 28, 2021, 6:55pm UTC](https://discourse.julialang.org/t/does-julia-have-equivalent-of-python-df-column-map-dict/47048/9 "2021-02-28T18:55:14Z")

</div>

This is a compilation time thing. Creating a new anonymous function has a fixed compilation cost, so `map(t -> ..., x)` is slow

```julia
julia> x = rand(1:5, 100);

julia> d = Dict(1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "E");

julia> @time getindex.(Ref(d), x);
  0.144137 seconds (172.92 k allocations: 9.074 MiB, 42.83% gc time)

julia> @time getindex.(Ref(d), x);
  0.000016 seconds (4 allocations: 976 bytes)

julia> @time map(xi -> d[xi], x);
  0.081783 seconds (98.49 k allocations: 5.256 MiB)

julia> @time map(xi -> d[xi], x);
  0.078627 seconds (55.19 k allocations: 2.922 MiB)

julia> get_from_d = let d = d
       xi -> d[xi]
       end;

julia> @time map(get_from_d, x);
  0.043167 seconds (43.72 k allocations: 2.272 MiB)

julia> @time map(get_from_d, x);
  0.000024 seconds (2 allocations: 928 bytes)

```

This re-compilation problem only shows up in global scope, though.

```julia
julia> function get_from_d_wrapper(d, x)
       map(xi -> d[xi], x)
       end;

julia> @time get_from_d_wrapper(d, x);
  0.037174 seconds (46.42 k allocations: 2.426 MiB)

julia> @time get_from_d_wrapper(d, x);
  0.000006 seconds (1 allocation: 896 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/does-julia-have-equivalent-of-python-df-column-map-dict/47048)._
