W4t*_*ind 6 arrays dataframe julia
我有一个数组 X,我想将其转换为数据帧。根据网络的推荐,我尝试转换为数据帧并收到以下错误。
julia> y=convert(DataFrame,x)
ERROR:转变has no method matching convert(::Type{DataFrame}, ::Array{Float64,2})
in convert at base.jl:13
当我尝试时DataFrame(x),转换有效,但我收到抱怨说转换已被弃用。
julia> DataFrame(x)
WARNING: DataFrame(::Matrix, ::Vector)) is deprecated, use convert(DataFrame, Matrix) instead in DataFrame at /Users/Matthew/.julia/v0.3/DataFrames/src/deprecated.jl:54 (repeats 2 times)
我应该注意另一种方法来保持我的代码一致吗?
编辑:Julia 0.3.2,DataFrames 0.5.10 OSX 10.9.5
julia> x=rand(4,4)
4x4 Array{Float64,2}:
0.467882 0.466358 0.28144 0.0151388
0.22354 0.358616 0.669564 0.828768
0.475064 0.187992 0.584741 0.0543435
0.0592643 0.345138 0.704496 0.844822
julia> convert(DataFrame,x)
ERROR: `convert` has no method matching convert(::Type{DataFrame}, ::Array{Float64,2}) in convert at base.jl:13
Run Code Online (Sandbox Code Playgroud)
这对我有用:
julia> using DataFrames
julia> x = rand(4, 4)
4x4 Array{Float64,2}:
0.790912 0.0367989 0.425089 0.670121
0.243605 0.62487 0.582498 0.302063
0.785159 0.0083891 0.881153 0.353925
0.618127 0.827093 0.577815 0.488565
julia> convert(DataFrame, x)
4x4 DataFrame
| Row | x1 | x2 | x3 | x4 |
|-----|----------|-----------|----------|----------|
| 1 | 0.790912 | 0.0367989 | 0.425089 | 0.670121 |
| 2 | 0.243605 | 0.62487 | 0.582498 | 0.302063 |
| 3 | 0.785159 | 0.0083891 | 0.881153 | 0.353925 |
| 4 | 0.618127 | 0.827093 | 0.577815 | 0.488565 |
Run Code Online (Sandbox Code Playgroud)
你在尝试不同的东西吗?
如果这不起作用,请尝试发布更多代码,我们可以更好地帮助您。
由于这是您在 google 上搜索时出现的第一件事,因此对于最新版本的DataFrames.jl,您现在可以使用该DataFrame()函数:
julia> x = rand(4,4)\n4\xc3\x974 Matrix{Float64}:\n 0.920406 0.738911 0.994401 0.9954\n 0.18791 0.845132 0.277577 0.231483\n 0.361269 0.918367 0.793115 0.988914\n 0.725052 0.962762 0.413111 0.328261\n\njulia> DataFrame(x, :auto)\n4\xc3\x974 DataFrame\n Row \xe2\x94\x82 x1 x2 x3 x4 \n \xe2\x94\x82 Float64 Float64 Float64 Float64 \n\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n 1 \xe2\x94\x82 0.920406 0.738911 0.994401 0.9954\n 2 \xe2\x94\x82 0.18791 0.845132 0.277577 0.231483\n 3 \xe2\x94\x82 0.361269 0.918367 0.793115 0.988914\n 4 \xe2\x94\x82 0.725052 0.962762 0.413111 0.328261\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
14181 次 |
| 最近记录: |