将Julia数组转换为数据框 [英] Convert Julia array to dataframe

查看:150
本文介绍了将Julia数组转换为数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组X,我想转换成一个数据框。根据网络推荐,我尝试转换为数据帧并获得以下错误。



julia> y = convert(DataFrame,x)
ERROR:
convert 没有匹配的方法convert(:: Type {DataFrame},:: Array {Float64,2})
转换为base.jl:13



当我尝试 DataFrame(x),转换有效,但我抱怨转换已被弃用。



julia> DataFrame(x)
警告:DataFrame(:: Matrix,:: Vector))已被弃用,请在/Users/Matthew/.julia/v0.3/DataFrames/src的DataFrame中使用convert(DataFrame,Matrix) /deprecated.jl:54(重复2次)



是否有其他方法我应该注意保持我的代码一致? p>

编辑:
朱莉娅0.3.2,
DataFrames 0.5.10
OSX 10.9.5

  julia> x = rand(4,4)
4x4数组{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)
错误:`convert`没有匹配convert(:: Type {DataFrame},:: Array {Float64,2})在base.jl中转换的方法:13


解决方案

我已经被同一个问题混淆了很多次,最终意识到这个问题通常与阵列的格式相关,并且可以通过在转换前简单地转换数组来轻松解决。



简而言之,我建议:

julia> convert(DataFrame,x')


I have an array X that I'd like to convert to a dataframe. Upon recommendation from the web, I tried converting to a dataframe and get the following error.

julia> y=convert(DataFrame,x) ERROR:converthas no method matching convert(::Type{DataFrame}, ::Array{Float64,2}) in convert at base.jl:13

When I try DataFrame(x), the conversion works but i get a complaint that the conversion is deprecated.

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)

Is there another method I should be aware of to keep my code consistent?

EDIT: 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

解决方案

I've been confounded by the same issue a number of times, and eventually realized the issue is often related to the format of the array, and is easily resolved by simply transposing the array prior to conversion.

In short, I recommend:
julia> convert(DataFrame, x')

这篇关于将Julia数组转换为数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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