Method: Daru::DataFrame#set_index

Defined in:
lib/daru/dataframe.rb

#set_index(new_index, opts = {}) ⇒ Object

Set a particular column as the new DF

Raises:

  • (ArgumentError)


1237
1238
1239
1240
1241
1242
1243
1244
1245
# File 'lib/daru/dataframe.rb', line 1237

def set_index new_index, opts={}
  raise ArgumentError, 'All elements in new index must be unique.' if
    @size != self[new_index].uniq.size

  self.index = Daru::Index.new(self[new_index].to_a)
  delete_vector(new_index) unless opts[:keep]

  self
end