Julia DataFrame输出功能 [英] Julia DataFrame output functions

查看:271
本文介绍了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("\n\n\n", "A = DataFrame(randn(10, 7))")

print("\n\n\n","print(A)\n")
print(A)

print("\n\n\n","show(A)\n")
show(A)

print("\n\n\n","show(A, true)\n")
show(A, true)

print("\n\n\n","show(A, false)\n")
show(A, false)

print("\n\n\n","showall(A)\n")
showall(A)

print("\n\n\n","showall(A, true)\n")
showall(A, true)

print("\n\n\n","showall(A, false)\n")
showall(A, false)

print("\n\n\n","display(A)\n")
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   │

这没关系,在笔记本中看起来还不错,并且可以将其正确输出到Latex/pdf,并使用nbconvert作为纯ascii文本表.但是,我希望有更多选项来获得类似于以下内容的文本输出,这在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天全站免登陆