# Multi-threading with DataFrames

**URL:** <https://discourse.julialang.org/t/multi-threading-with-dataframes/101859>\
**Category:** General Usage\
**Tags:** multithreading, dataframes\
**Created:** [July 20, 2023, 10:16pm UTC](https://discourse.julialang.org/t/multi-threading-with-dataframes/101859 "2023-07-20T22:16:35Z")\
**Posts on this page:** 1\
**Showing post:** 32

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [December 22, 2023, 11:18pm UTC](https://discourse.julialang.org/t/multi-threading-with-dataframes/101859/32 "2023-12-22T23:18:56Z")

</div>

```julia
julia> using DataFrames, Symbolics

julia> df_flows = DataFrame(;
           from = ["p1", "p1", "p2", "p2", "p1", "p2"],
           to = ["d", "d", "d", "d", "d", "d"],
           rp = [1, 1, 1, 1, 2, 2],
           tb = [3,5,7,4,6,8],
           index = 1:6,
       )
6×5 DataFrame
 Row │ from to rp tb index 
     │ String String Int64 Int64 Int64 
─────┼─────────────────────────────────────
   1 │ p1 d 1 3 1
   2 │ p1 d 1 5 2
   3 │ p2 d 1 7 3
   4 │ p2 d 1 4 4
   5 │ p1 d 2 6 5
   6 │ p2 d 2 8 6

julia> @variables x y z
3-element Vector{Num}:
 x
 y
 z

julia> w=x^2+y*sqrt(z*x)
x^2 + y*sqrt(x*z)

julia> transform(df_flows,[3,4,5]=>ByRow((r,t,i)->substitute(w, Dict(x=>r,y=>t,z=>i))))
6×6 DataFrame
 Row │ from to rp tb index rp_tb_index_function   
     │ String String Int64 Int64 Int64 Num
─────┼───────────────────────────────────────────────────────────  
   1 │ p1 d 1 3 1 4.0       
   2 │ p1 d 1 5 2 8.07107   
   3 │ p2 d 1 7 3 13.1244    
   4 │ p2 d 1 4 4 9.0       
   5 │ p1 d 2 6 5 22.9737    
   6 │ p2 d 2 8 6 31.7128    

julia> w=3x-2y
3x - 2y

julia> transform(df_flows,[3,4,5]=>ByRow((r,t,i)->substitute(w, Dict(x=>r,y=>t,z=>i))))
6×6 DataFrame
 Row │ from to rp tb index rp_tb_index_function   
     │ String String Int64 Int64 Int64 Num
─────┼───────────────────────────────────────────────────────────  
   1 │ p1 d 1 3 1 -3   
   2 │ p1 d 1 5 2 -7   
   3 │ p2 d 1 7 3 -11   
   4 │ p2 d 1 4 4 -5   
   5 │ p1 d 2 6 5 -6   
   6 │ p2 d 2 8 6 -10   

```

PS  
I saw several [old posts](https://discourse.julialang.org/t/convert-string-to-function-name/1547) that discussed the problem of deriving a function from a string. Apart from the solution with parse() and eval() I have seen the use of the getfield function applied to the current module to obtain the function from the string.  
But this applies to functions already defined in the module.  
An equivalent would be, in my opinion, a dict with strings as keys and functions as values.

---

_[View the full topic](https://discourse.julialang.org/t/multi-threading-with-dataframes/101859)._
