Julia DataFrame 输出函数 [英] Julia DataFrame output functions

查看:17
本文介绍了Julia DataFrame 输出函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些 Julia 函数可以输出 DataFrame,以便将其转换为下面显示的文本以外的文本?

What Julia functions can output a DataFrame so it is converted into text other than the ones shown below?

using DataFrames
A = DataFrame(randn(10, 7));

print("


", "A = DataFrame(randn(10, 7))")

print("


","print(A)
")
print(A)

print("


","show(A)
")
show(A)

print("


","show(A, true)
")
show(A, true)

print("


","show(A, false)
")
show(A, false)

print("


","showall(A)
")
showall(A)

print("


","showall(A, true)
")
showall(A, true)

print("


","showall(A, false)
")
showall(A, false)

print("


","display(A)
")
display(A)

大部分输出类似于以下内容:

Most of these output something similar to the following:

10×7 DataFrames.DataFrame
│ Row │ x1         │ x2        │ x3        │ x4        │ x5         │ x6        │ x7        │
├─────┼────────────┼───────────┼───────────┼───────────┼────────────┼───────────┼───────────┤
│ 1   │ 0.377968   │ -2.23532  │ 0.560632  │ 1.00294   │ 1.32404    │ 1.30788   │ -2.09068  │
│ 2   │ -0.694824  │ -0.765572 │ -1.11163  │ 0.038083  │ -0.52553   │ -0.571156 │ 0.977219  │
│ 3   │ 0.343035   │ -1.47047  │ 0.228148  │ -1.29784  │ -1.00742   │ 0.127103  │ -0.399041 │
│ 4   │ -0.0979587 │ -0.445756 │ -0.483188 │ 0.816921  │ -1.12535   │ 0.603824  │ 0.293274  │
│ 5   │ 1.12755    │ -1.62993  │ 0.178764  │ -0.201441 │ -0.730923  │ 0.230186  │ -0.679262 │
│ 6   │ 0.481705   │ -0.716072 │ 0.747341  │ -0.310009 │ 1.4159     │ -0.175918 │ -0.079051 │
│ 7   │ 0.732061   │ -1.08842  │ -1.18988  │ 0.577758  │ -1.474     │ -1.43082  │ -0.584148 │
│ 8   │ -1.077     │ -1.41973  │ -0.330143 │ -1.12357  │ 1.01005    │ 1.06746   │ 2.09197   │
│ 9   │ -1.60122   │ -1.44661  │ 0.299586  │ 1.46604   │ -0.0200695 │ 2.62421   │ 0.396777  │
│ 10  │ -1.74101   │ -0.541589 │ 0.425117  │ 0.14669   │ 0.95779    │ 1.73954   │ -1.7994   │

这没问题,在笔记本中看起来不错,并且可以使用 nbconvert 作为纯 ascii 文本表正确输出到 latex/pdf.但是,我想要更多选项来获得类似于以下内容的文本输出,这在 nbconvert 生成的 Latex/pdf 中看起来要好得多.

This is ok and looks decent in a notebook, and is output correctly to latex/pdf with nbconvert as a plain ascii text table. However, I want more options to get text output similar to the following which looks much better in the latex/pdf generated by nbconvert.

|  Column 1  | Column 2 | Column 3 | Column 4 |
|-------|-------------|-------------|--------------|
| a | b | c | d |
| A | B | C | D |

是否有任何函数可以输出具有这种格式的 Julia DataFrame?digits =caption = 等其他参数呢?

Are there any functions that output a Julia DataFrame with this formatting? What about other parameters like digits = or caption =?

推荐答案

查看源代码,没有开箱即用的方法.您必须自己编写(然后您可以为 github 存储库做出贡献).

Looking at the source code, there isn't an out-of-the-box way. You'll have to write your own (which you can then contribute to the github repo).

最简单的方法是利用输出 writetable() 到内存文件(使用 | 作为分隔符),然后处理列标题

Easiest way to do this is to make use of the output writetable() to an in-memory file (using | as a separator) and then handle the column headers

这篇关于Julia DataFrame 输出函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆