Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataFrames.jl Number of rows

I'd like to get the number of rows of a dataframe. I can achieve that with size(myDataFrame)[1]. Is there a cleaner way ?

like image 495
Neabfi Avatar asked Jun 24 '16 14:06

Neabfi


People also ask

What are DataFrames in Julia?

Julia has a library to handle tabular data, in a way similar to R or Pandas dataframes. The name is, no surprises, DataFrames. The approach and the function names are similar, although the way of actually accessing the API may be a bit different.

How do you create a data frame in Julia?

Steps to Create a DataFrame in Julia from Scratch You can then use the following template to create a DataFrame in Julia: using DataFrames df = DataFrame(column_1 = ["value_1", "value_2", "value_3", ...], column_2 = ["value_1", "value_2", "value_3", ...], column_3 = ["value_1", "value_2", "value_3", ...], ... )

How do I create an empty DataFrame in Julia?

Create an empty Julia DataFrame by enclosing column names and datatype of column inside DataFrame() function. Now you can add rows one by one using push!() function. This is like row binding.


1 Answers

If you are using DataFrames specifically, then you can use nrow():

julia> df = DataFrame(Any[1:10, 1:10]);
julia> nrow(df)
10

Alternatively, you can specify the dimension argument for size:

julia> size(df, 1)
10

This also work for arrays as well so it's a bit more general:

julia> my_array = rand(4, 3)
4×3 Array{Float64,2}:
 0.980798  0.873643  0.819478
 0.341972  0.34974   0.160342
 0.262292  0.387406  0.00741398
 0.512669  0.81579   0.329353

julia> size(my_array, 1)
4
like image 55
niczky12 Avatar answered Oct 21 '22 00:10

niczky12