Drop the first n rows from daru dataframe

199 views Asked by At

One can drop the first n elements of an array by using Array#drop.

a = [1,2,3]
a.drop(2) # => [3]

I want to drop the first n rows from a Daru::DataFrame object. It seems this class does not implement such drop method.

How can I delete the first n rows from a Daru::DataFrame object?

2

There are 2 answers

0
richflow On BEST ANSWER

You can use row_at to retrieve all the rows without the first 4.

Example:

2.4.5 :001 > require 'daru'
 => true
2.4.5 :002 > df = Daru::DataFrame.new({
2.4.5 :003 >         'col0' => [1,2,3,4,5,6],
2.4.5 :004 >         'col2' => ['a','b','c','d','e','f'],
2.4.5 :005 >         'col1' => [11,22,33,44,55,66]
2.4.5 :006?>       })
 => #<Daru::DataFrame(6x3)>
      col0 col2 col1
    0    1    a   11
    1    2    b   22
    2    3    c   33
    3    4    d   44
    4    5    e   55
    5    6    f   66

Retrieve rows:

2.4.5 :010 > df.row_at(4..df.shape()[0])
 => #<Daru::DataFrame(2x3)>
      col0 col2 col1
    4    5    e   55
    5    6    f   66
0
simon tan On