// SetColNames sets the names of the columns of the DataFrame to the given names
SetColNames sets the names of the columns of the DataFrame to the given names
// SetColNames sets the names of the columns of the DataFrame to the given names
func (df *DF) SetColNames(names ...string) error {
	if len(names) == 0 {
		err := ErrNoNamesGiven
		df.addError(err)
		return err
	}
	if len(df.mci.info) == 0 {
		df.mci.info = make([]ColInfo, len(names))
	} else if len(df.mci.info) != len(names) {
		err := dfError(fmt.Sprintf(
			"the number of columns (%d) and number of names (%d) differ",
			len(df.mci.info), len(names)))
		df.addError(err)
		return err
	}
	colNameToIdx := make(map[string]int, len(names))
	for i, name := range names {
		if dup, exists := colNameToIdx[name]; exists {
			err := dfError(fmt.Sprintf(
				"duplicate column name: %q is used for columns %d and %d",
				name, dup, i))
			df.addError(err)
			return err
		}
		colNameToIdx[name] = i
	}
	for i, name := range names {
		df.mci.info[i].name = name
	}
	df.mci.nameToCol = colNameToIdx
	return nil
}
func ( df * DF ) SetColNames ( names ... string ) error { if len ( names ) == 0 { err := ErrNoNamesGiven df . addError ( err ) return err } if len ( df . mci . info ) == 0 { df . mci . info = make ( [ ] ColInfo , len ( names ) ) } else if len ( df . mci . info ) != len ( names ) { err := dfError ( fmt . Sprintf ( " " , len ( df . mci . info ) , len ( names ) ) ) df . addError ( err ) return err } colNameToIdx := make ( map [ string ] int , len ( names ) ) for i , name := range names { if dup , exists := colNameToIdx [ name ] ; exists { err := dfError ( fmt . Sprintf ( " " , name , dup , i ) ) df . addError ( err ) return err } colNameToIdx [ name ] = i } for i , name := range names { df . mci . info [ i ] . name = name } df . mci . nameToCol = colNameToIdx return nil }
SetColNames sets the names of the columns of the DataFrame to the given names
SetColNames sets the names of the columns of the DataFrame to the given names