h2o-py/h2o/frame.py
def drop(self, index, axis=1):
        """
        Drop a single column or row or a set of columns or rows from a H2OFrame.

        Dropping a column or row is not in-place.
        Indices of rows and columns are zero-based.

        :param index: A list of column indices, column names, or row indices to drop; or
            a string to drop a single column by name; or an int to drop a single column by index.

        :param int axis: If 1 (default), then drop columns; if 0 then drop rows.

        :returns: a new H2OFrame with the respective dropped columns or rows. The original H2OFrame remains
            unchanged.
        """
        if axis == 1:
            if not isinstance(index, list):
                #If input is a string, i.e., "C1":
                if is_type(index, str):
                    #Check if index is an actual column(s) in the frame
                    if index not in self.names:
                        raise H2OValueError("Column(s) selected to drop are not in original frame: %r" % index)
                    index = self.names.index(index)
                #If input is an int indicating a column index, i.e., 3:
                elif is_type(index, int):
                    #Check if index is an actual column index in the frame
                    if index > self.ncol:
                        raise H2OValueError("Column index selected to drop is not part of the frame: %r" % index)
                    if index < 0:
                        raise H2OValueError("Column index selected to drop is not positive: %r" % index)

                fr = H2OFrame._expr(expr=ExprNode("cols", self, -(index + 1)), cache=self._ex._cache)
                fr._ex._cache.ncols -= 1
                fr._ex._cache.names = self.names[:index] + self.names[index + 1:]
                fr._ex._cache.types = {name: self.types[name] for name in fr._ex._cache.names}
                return fr

            elif isinstance(index, list):
                #If input is an int array indicating a column index, i.e., [3] or [1,2,3]:
                if is_type(index, [int]):
                    if max(index) > self.ncol:
                        raise H2OValueError("Column index selected to drop is not part of the frame: %r" % index)
                    if min(index) < 0:
                        raise H2OValueError("Column index selected to drop is not positive: %r" % index)
                    for i in range(len(index)):
                        index[i] = -(index[i] + 1)
                #If index is a string array, i.e., ["C1", "C2"]
                elif is_type(index, [str]):
                    #Check if index is an actual column(s) in the frame
                    if not set(index).issubset(self.names):
                        raise H2OValueError("Column(s) selected to drop are not in original frame: %r" % index)
                    for i in range(len(index)):
                        index[i] = -(self.names.index(index[i]) + 1)
                fr = H2OFrame._expr(expr=ExprNode("cols", self, index), cache=self._ex._cache)
                fr._ex._cache.ncols -= len(index)
                fr._ex._cache.names = [i for i in self.names
                                       if self.names.index(i) not in list(map(lambda x: abs(x) - 1, index))]
                fr._ex._cache.types = {name: fr.types[name] for name in fr._ex._cache.names}

            else:
                raise ValueError("Invalid column index types. Must either be a list of all int indexes, "
                                 "a string list of all column names, a single int index, or"
                                 "a single string for dropping columns.")
            return fr
        elif axis == 0:
            if is_type(index, [int]):
                #Check if index is an actual column index in the frame
                if max(index) > self.nrow:
                    raise H2OValueError("Row index selected to drop is not part of the frame: %r" % index)
                if min(index) < 0:
                    raise H2OValueError("Row index selected to drop is not positive: %r" % index)
                index = [-(x + 1) for x in index]
                fr = H2OFrame._expr(expr=ExprNode("rows", self, index), cache=self._ex._cache)
                fr._ex._cache.nrows -= len(index)
            else:
                raise ValueError("Invalid row indexes. Must be a list of int row indexes to drop from the H2OFrame.")
        return fr
def drop(self, index, axis=1):
        """
        Drop a single column or row or a set of columns or rows from a H2OFrame.

        Dropping a column or row is not in-place.
        Indices of rows and columns are zero-based.

        :param index: A list of column indices, column names, or row indices to drop; or
            a string to drop a single column by name; or an int to drop a single column by index.

        :param int axis: If 1 (default), then drop columns; if 0 then drop rows.

        :returns: a new H2OFrame with the respective dropped columns or rows. The original H2OFrame remains
            unchanged.
        """
        if axis == 1:
            if not isinstance(index, list):
                #If input is a string, i.e., "C1":
                if is_type(index, str):
                    #Check if index is an actual column(s) in the frame
                    if index not in self.names:
                        raise H2OValueError("Column(s) selected to drop are not in original frame: %r" % index)
                    index = self.names.index(index)
                #If input is an int indicating a column index, i.e., 3:
                elif is_type(index, int):
                    #Check if index is an actual column index in the frame
                    if index > self.ncol:
                        raise H2OValueError("Column index selected to drop is not part of the frame: %r" % index)
                    if index < 0:
                        raise H2OValueError("Column index selected to drop is not positive: %r" % index)

                fr = H2OFrame._expr(expr=ExprNode("cols", self, -(index + 1)), cache=self._ex._cache)
                fr._ex._cache.ncols -= 1
                fr._ex._cache.names = self.names[:index] + self.names[index + 1:]
                fr._ex._cache.types = {name: self.types[name] for name in fr._ex._cache.names}
                return fr

            elif isinstance(index, list):
                #If input is an int array indicating a column index, i.e., [3] or [1,2,3]:
                if is_type(index, [int]):
                    if max(index) > self.ncol:
                        raise H2OValueError("Column index selected to drop is not part of the frame: %r" % index)
                    if min(index) < 0:
                        raise H2OValueError("Column index selected to drop is not positive: %r" % index)
                    for i in range(len(index)):
                        index[i] = -(index[i] + 1)
                #If index is a string array, i.e., ["C1", "C2"]
                elif is_type(index, [str]):
                    #Check if index is an actual column(s) in the frame
                    if not set(index).issubset(self.names):
                        raise H2OValueError("Column(s) selected to drop are not in original frame: %r" % index)
                    for i in range(len(index)):
                        index[i] = -(self.names.index(index[i]) + 1)
                fr = H2OFrame._expr(expr=ExprNode("cols", self, index), cache=self._ex._cache)
                fr._ex._cache.ncols -= len(index)
                fr._ex._cache.names = [i for i in self.names
                                       if self.names.index(i) not in list(map(lambda x: abs(x) - 1, index))]
                fr._ex._cache.types = {name: fr.types[name] for name in fr._ex._cache.names}

            else:
                raise ValueError("Invalid column index types. Must either be a list of all int indexes, "
                                 "a string list of all column names, a single int index, or"
                                 "a single string for dropping columns.")
            return fr
        elif axis == 0:
            if is_type(index, [int]):
                #Check if index is an actual column index in the frame
                if max(index) > self.nrow:
                    raise H2OValueError("Row index selected to drop is not part of the frame: %r" % index)
                if min(index) < 0:
                    raise H2OValueError("Row index selected to drop is not positive: %r" % index)
                index = [-(x + 1) for x in index]
                fr = H2OFrame._expr(expr=ExprNode("rows", self, index), cache=self._ex._cache)
                fr._ex._cache.nrows -= len(index)
            else:
                raise ValueError("Invalid row indexes. Must be a list of int row indexes to drop from the H2OFrame.")
        return fr
def drop ( self , index , axis = 1 ) : if axis == 1 : if not isinstance ( index , list ) : #If input is a string, i.e., "C1": if is_type ( index , str ) : #Check if index is an actual column(s) in the frame if index not in self . names : raise H2OValueError ( "Column(s) selected to drop are not in original frame: %r" % index ) index = self . names . index ( index ) #If input is an int indicating a column index, i.e., 3: elif is_type ( index , int ) : #Check if index is an actual column index in the frame if index > self . ncol : raise H2OValueError ( "Column index selected to drop is not part of the frame: %r" % index ) if index < 0 : raise H2OValueError ( "Column index selected to drop is not positive: %r" % index ) fr = H2OFrame . _expr ( expr = ExprNode ( "cols" , self , - ( index + 1 ) ) , cache = self . _ex . _cache ) fr . _ex . _cache . ncols -= 1 fr . _ex . _cache . names = self . names [ : index ] + self . names [ index + 1 : ] fr . _ex . _cache . types = { name : self . types [ name ] for name in fr . _ex . _cache . names } return fr elif isinstance ( index , list ) : #If input is an int array indicating a column index, i.e., [3] or [1,2,3]: if is_type ( index , [ int ] ) : if max ( index ) > self . ncol : raise H2OValueError ( "Column index selected to drop is not part of the frame: %r" % index ) if min ( index ) < 0 : raise H2OValueError ( "Column index selected to drop is not positive: %r" % index ) for i in range ( len ( index ) ) : index [ i ] = - ( index [ i ] + 1 ) #If index is a string array, i.e., ["C1", "C2"] elif is_type ( index , [ str ] ) : #Check if index is an actual column(s) in the frame if not set ( index ) . issubset ( self . names ) : raise H2OValueError ( "Column(s) selected to drop are not in original frame: %r" % index ) for i in range ( len ( index ) ) : index [ i ] = - ( self . names . index ( index [ i ] ) + 1 ) fr = H2OFrame . _expr ( expr = ExprNode ( "cols" , self , index ) , cache = self . _ex . _cache ) fr . _ex . _cache . ncols -= len ( index ) fr . _ex . _cache . names = [ i for i in self . names if self . names . index ( i ) not in list ( map ( lambda x : abs ( x ) - 1 , index ) ) ] fr . _ex . _cache . types = { name : fr . types [ name ] for name in fr . _ex . _cache . names } else : raise ValueError ( "Invalid column index types. Must either be a list of all int indexes, " "a string list of all column names, a single int index, or" "a single string for dropping columns." ) return fr elif axis == 0 : if is_type ( index , [ int ] ) : #Check if index is an actual column index in the frame if max ( index ) > self . nrow : raise H2OValueError ( "Row index selected to drop is not part of the frame: %r" % index ) if min ( index ) < 0 : raise H2OValueError ( "Row index selected to drop is not positive: %r" % index ) index = [ - ( x + 1 ) for x in index ] fr = H2OFrame . _expr ( expr = ExprNode ( "rows" , self , index ) , cache = self . _ex . _cache ) fr . _ex . _cache . nrows -= len ( index ) else : raise ValueError ( "Invalid row indexes. Must be a list of int row indexes to drop from the H2OFrame." ) return fr
Drop a single column or row or a set of columns or rows from a H2OFrame.

        Dropping a column or row is not in-place.
        Indices of rows and columns are zero-based.

        :param index: A list of column indices, column names, or row indices to drop; or
            a string to drop a single column by name; or an int to drop a single column by index.

        :param int axis: If 1 (default), then drop columns; if 0 then drop rows.

        :returns: a new H2OFrame with the respective dropped columns or rows. The original H2OFrame remains
            unchanged.
Drop a single column or row or a set of columns or rows from a H2OFrame .