In the following link, we see that we can use a table
package in Python to return in orgtbl format.
#+begin_src python :results value raw :output :return tabulate(df, headers=df.columns, tablefmt='orgtbl')
from tabulate import tabulate
import pandas as pd
df = pd.DataFrame({
"a": [1,2,3],
"b": [4,5,6]
})
#+end_src
#+RESULTS:
| | a | b |
|---+---+---|
| 0 | 1 | 4 |
| 1 | 2 | 5 |
| 2 | 3 | 6 |
Get pandas data-frame as a table in org-babel
But, how can we do that in Julia? I know It's possible to utilize PyCall to import and use Python libraries. But, I seem unable to pull this one off.
What I have until now:
#+begin_src julia :session main :result output
tabulate.tabulate
#+end_src
#+RESULTS:
: PyObject <function tabulate at 0x7f182faaab80>
Trying to output calling tabulate.tabulate (doesn't work),
#+begin_src julia :session main :return tabulate.tabulate(py"df_raw, headers=df_raw.columns, tablefmt='orgtbl'")
@chain df_raw begin
groupby([:target, :sex])
combine(nrow)
end
#+end_src
Also doesn't work,
tabulate.tabulate(py"df_raw, headers=df_raw.columns, tablefmt='orgtbl'")
or tabulate.tabulate(df_raw)
With the following error:
julia> tabulate.tabulate(df_raw)
ERROR: (in a Julia function called from Python)
JULIA: AbstractDataFrame is not iterable. Use eachrow(df) to get a row iterator or eachcol(df) to get a column iterator
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] iterate(#unused#::DataFrame)
@ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/abstractdataframe/iteration.jl:23
NOTE: df_raw is a random DataFrame,
help?> df_raw
search: df_raw dof_residual default_cgrad
No documentation found.
df_raw is of type DataFrame.
Summary
≡≡≡≡≡≡≡≡≡
struct DataFrame <: AbstractDataFrame
Fields
≡≡≡≡≡≡≡≡
columns :: Vector{AbstractVector{T} where T}
colindex :: DataFrames.Index
Supertype Hierarchy
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
DataFrame <: AbstractDataFrame <: Any