Convert data frame with label to array in julia

I have a data frame with a header in Julia, but I need to convert this to an array for some filtering, there is a similar record that people suggest using:

iris[:, 1:3]

to get an array from a dataframe, but this method will not work with a dataframe with a header, any suggestion, what should I do?

data format:

FP | C1 | Cz | C2 ....
*  | *  | *  | *  ....
.  | .  | .  | .  ....
.  | .  | .  | .  ....
.  | .  | .  | .  ....
+14
source share
5 answers

Have you tried convert(Matrix, iris[:,1:3])? eg,

julia> using DataFrames

julia> df = DataFrame(a = 1:4, b = 1:4, c = randn(4), d = randn(4))
4Γ—4 DataFrame
β”‚ Row β”‚ a     β”‚ b     β”‚ c        β”‚ d          β”‚
β”‚     β”‚ Int64 β”‚ Int64 β”‚ Float64  β”‚ Float64    β”‚
β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1   β”‚ 1     β”‚ 1     β”‚ 1.72172  β”‚ -0.377729  β”‚
β”‚ 2   β”‚ 2     β”‚ 2     β”‚ 0.206415 β”‚ -0.266014  β”‚
β”‚ 3   β”‚ 3     β”‚ 3     β”‚ 1.03785  β”‚ -0.0317582 β”‚
β”‚ 4   β”‚ 4     β”‚ 4     β”‚ 0.632473 β”‚ -0.409014  β”‚

julia> convert(Matrix, df[:,1:3])
4Γ—3 Array{Float64,2}:
 1.0  1.0  1.72172
 2.0  2.0  0.206415
 3.0  3.0  1.03785
 4.0  4.0  0.632473
+18
source

The accepted answer is well suited to answer the question as indicated.

, DataFrame , - , , , , DataFrame . . https://dataframesjl.readthedocs.io/en/latest/subsets.html https://dataframesjl.readthedocs.io/en/latest/split_apply_combine.html.

(, , - , .)

+7

convert, , convert(::Type{Array}, df::AbstractDataFrame) :

using DataFrames
convert(Matrix, df)

Matrix(df)

+2

Julia 0.7 . , Matrix(df) .

0

convert(Array, iris[:,1:3]) Julia 1.1.1

0

Source: https://habr.com/ru/post/1672864/


All Articles