// ApplyToColumn creates a new DataFrame with the new column appended. The new column is built
// with the response values obtained from ApplyToColumnFunc. An error response value from
// ApplyToColumnFunc will cause ApplyToColumn to return immediately.
ApplyToColumn creates a new DataFrame with the new column appended. The new column is built
with the response values obtained from ApplyToColumnFunc. An error response value from
ApplyToColumnFunc will cause ApplyToColumn to return immediately.
// ApplyToColumn creates a new DataFrame with the new column appended . The new column is built // with the response values obtained from ApplyToColumnFunc . An error response value from // ApplyToColumnFunc will cause ApplyToColumn to return immediately .
func (df *DataFrame) ApplyToColumn(columnName, newColumnName string, fn ApplyToColumnFunc) (*DataFrame, error) {
	return df.Apply(func(df *DataFrame) (*DataFrame, error) {
		col := df.Column(columnName)
		field := col.Field()
		field.Name = newColumnName
		schema := arrow.NewSchema([]arrow.Field{field}, nil)
		builder := array.NewRecordBuilder(df.Allocator(), schema)
		defer builder.Release()
		smartBuilder := smartbuilder.NewSmartBuilder(builder)
		valueIterator := iterator.NewValueIterator(col)
		defer valueIterator.Release()
		for valueIterator.Next() {
			value := valueIterator.ValueInterface()
			res, err := fn(value)
			if err != nil {
				return nil, err
			}
			smartBuilder.Append(0, res)
		}
		rec := builder.NewRecord()
		defer rec.Release()
		chunk := array.NewChunked(col.DataType(), rec.Columns())
		defer chunk.Release()
		newCol := array.NewColumn(field, chunk)
		defer newCol.Release()
		return df.AppendColumn(newCol)
	})
}
func ( df * DataFrame ) ApplyToColumn ( columnName , newColumnName string , fn ApplyToColumnFunc ) ( * DataFrame , error ) { return df . Apply ( func ( df * DataFrame ) ( * DataFrame , error ) { col := df . Column ( columnName ) field := col . Field ( ) field . Name = newColumnName schema := arrow . NewSchema ( [ ] arrow . Field { field } , nil ) builder := array . NewRecordBuilder ( df . Allocator ( ) , schema ) defer builder . Release ( ) smartBuilder := smartbuilder . NewSmartBuilder ( builder ) valueIterator := iterator . NewValueIterator ( col ) defer valueIterator . Release ( ) for valueIterator . Next ( ) { value := valueIterator . ValueInterface ( ) res , err := fn ( value ) if err != nil { return nil , err } smartBuilder . Append ( 0 , res ) } rec := builder . NewRecord ( ) defer rec . Release ( ) chunk := array . NewChunked ( col . DataType ( ) , rec . Columns ( ) ) defer chunk . Release ( ) newCol := array . NewColumn ( field , chunk ) defer newCol . Release ( ) return df . AppendColumn ( newCol ) } ) }
ApplyToColumn creates a new DataFrame with the new column appended.
ApplyToColumn creates a new DataFrame with the new column appended .
// TODO(nickpoorman): refactor this