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]

|   | 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

: 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])

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
  [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.


  struct DataFrame <: AbstractDataFrame


  columns  :: Vector{AbstractVector{T} where T}
  colindex :: DataFrames.Index

  Supertype Hierarchy

  DataFrame <: AbstractDataFrame <: Any
  • This is a question about Julia and not about Emacs in any way.
    – db48x
    Sep 8, 2021 at 22:39
  • It is about Org mode, so it is about Emacs in a way.
    – NickD
    Sep 9, 2021 at 1:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.