Module: DaruLite::DataFrame::Missable

Extended by:
Gem::Deprecate
Included in:
DaruLite::DataFrame
Defined in:
lib/daru_lite/data_frame/missable.rb

Instance Method Summary collapse

Instance Method Details

#has_missing_data?Boolean Also known as: flawed?

Returns:

  • (Boolean)


67
68
69
# File 'lib/daru_lite/data_frame/missable.rb', line 67

def has_missing_data?
  @data.any? { |vec| vec.include_values?(*DaruLite::MISSING_VALUES) }
end

#missing_values_rows(missing_values = [nil]) ⇒ Object Also known as: vector_missing_values

Return a vector with the number of missing values in each row.

Arguments

  • missing_values - An Array of the values that should be

treated as ‘missing’. The default missing value is nil.



56
57
58
59
60
61
62
# File 'lib/daru_lite/data_frame/missable.rb', line 56

def missing_values_rows(missing_values = [nil])
  number_of_missing = each_row.map do |row|
    row.indexes(*missing_values).size
  end

  DaruLite::Vector.new number_of_missing, index: @index, name: "#{@name}_missing_rows"
end

#rolling_fillna(direction = :forward) ⇒ Object



46
47
48
# File 'lib/daru_lite/data_frame/missable.rb', line 46

def rolling_fillna(direction = :forward)
  dup.rolling_fillna!(direction)
end

#rolling_fillna!(direction = :forward) ⇒ Object

Rolling fillna replace all Float::NAN and NIL values with the preceeding or following value

Examples:

df = DaruLite::DataFrame.new({
 a: [1,    2,          3,   nil,        Float::NAN, nil, 1,   7],
 b: [:a,  :b,          nil, Float::NAN, nil,        3,   5,   nil],
 c: ['a',  Float::NAN, 3,   4,          3,          5,   nil, 7]
})

=> #<DaruLite::DataFrame(8x3)>
     a   b   c
 0   1   a   a
 1   2   b NaN
 2   3 nil   3
 3 nil NaN   4
 4 NaN nil   3
 5 nil   3   5
 6   1   5 nil
 7   7 nil   7

2.3.3 :068 > df.rolling_fillna(:forward)
=> #<DaruLite::DataFrame(8x3)>
     a   b   c
 0   1   a   a
 1   2   b   a
 2   3   b   3
 3   3   b   4
 4   3   b   3
 5   3   3   5
 6   1   5   5
 7   7   5   7

Parameters:

  • direction (Symbol) (defaults to: :forward)

    (:forward, :backward) whether replacement value is preceeding or following



41
42
43
44
# File 'lib/daru_lite/data_frame/missable.rb', line 41

def rolling_fillna!(direction = :forward)
  @data.each { |vec| vec.rolling_fillna!(direction) }
  self
end