使用writetable将DataFrame中的字符串写入文件的默认设置是它们被引号括起来:
using DataFrames
df = DataFrame(letters=["A","B","C"],numbers=[1,2,3])
writetable("df_file", df, separator='\t')
Run Code Online (Sandbox Code Playgroud)
生成以下文件:
"letters" "numbers"
"A" 1
"B" 2
"C" 3
Run Code Online (Sandbox Code Playgroud)
可以选择更改引号字符:
writetable("df_file", df, separator='\t', quotemark='.')
.letters. .numbers.
.A. 1
.B. 2
.C. 3
Run Code Online (Sandbox Code Playgroud)
但如果没有指定字符,这不起作用
writetable("df_file", df, separator='\t', quotemark='')
ERROR: syntax: invalid character literal
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何编写没有任何引号字符的字符串?这将是我需要的输出:
letters numbers
A 1
B 2
C 3
Run Code Online (Sandbox Code Playgroud)
我目前正在使用Julia版本0.4.1,DataFrames软件包版本0.6.10.
我有一个包含单个项目的集合,在本例中是一个字符串:
b = Set(["A"])
Run Code Online (Sandbox Code Playgroud)
我想把那个单品拿出来.这样做的最佳方法是什么?我能想到的唯一方法是使用循环:
single_item = ""
for item in b
single_item = item
end
Run Code Online (Sandbox Code Playgroud)
这得到了我需要的东西
julia> single_item
"A"
Run Code Online (Sandbox Code Playgroud)
但我觉得必须有一个更简单的方法.
我有以下图表,其中图例遮盖了部分数据:
using Plots; gr()
using StatPlots
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)))
Run Code Online (Sandbox Code Playgroud)
我可以看到,使用“ legend”属性,可以将图例移动到绘图区域内的各个位置,例如:
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将图例完全移至绘图区域之外,例如移至绘图的右侧或下方吗?对于这些堆积的条形图,在图区内部确实没有图例的好位置。到目前为止,我唯一能想到的解决方案是在输入数据矩阵中创建一些“虚假”的空行,以使空间中带有一些零,但这似乎有点棘手,并且需要进行一些摆弄才能获得正确的结果。每次绘制时的额外行数:
groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
Run Code Online (Sandbox Code Playgroud)
我可以看到,有人针对pyplot提出了某种解决方案,有人知道GR后端有类似的解决方案吗?我可以想象的另一个解决方案-是否可以将图例本身保存到其他文件中,然后再将它们重新放在Inkscape中?
我尝试过以下方法:
using Plots.jl; gr()
histogram(randn(1000),yaxis=(:log10))
Run Code Online (Sandbox Code Playgroud)
它会产生以下错误
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: At least one finite value must be provided to formatter.
in showoff(::Array{Float64,1}, ::Symbol) at /Users/ianmarshall/.julia/v0.5/Showoff/src/Showoff.jl:120
in optimal_ticks_and_labels(::Plots.Axis, ::Void) at /Users/ianmarshall/.julia/v0.5/Plots/src/axes.jl:176
in get_ticks(::Plots.Axis) at /Users/ianmarshall/.julia/v0.5/Plots/src/axes.jl:204
in axis_drawing_info(::Plots.Subplot{Plots.GRBackend}) at /Users/ianmarshall/.julia/v0.5/Plots/src/axes.jl:452
in gr_display(::Plots.Subplot{Plots.GRBackend}, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Array{Float64,1}) at /Users/ianmarshall/.julia/v0.5/Plots/src/backends/gr.jl:570
in gr_display(::Plots.Plot{Plots.GRBackend}) at /Users/ianmarshall/.julia/v0.5/Plots/src/backends/gr.jl:457
in _display(::Plots.Plot{Plots.GRBackend}) at /Users/ianmarshall/.julia/v0.5/Plots/src/backends/gr.jl:1004
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Plots.Plot{Plots.GRBackend}) at /Users/ianmarshall/.julia/v0.5/Plots/src/output.jl:120
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Plots.Plot{Plots.GRBackend}) at ./REPL.jl:135
in display(::Plots.Plot{Plots.GRBackend}) at ./multimedia.jl:143
in print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:154 …Run Code Online (Sandbox Code Playgroud)