Julia DataFrame output functions

旧巷老猫 提交于 2020-01-23 07:56:48

问题


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   │

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 |

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


回答1:


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

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



来源:https://stackoverflow.com/questions/38341004/julia-dataframe-output-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!