INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
Extract columns names and python typos from metadata
def get_table_columns(metadata): """ Extract columns names and python typos from metadata Args: metadata: Table metadata Returns: dict with columns names and python types """ cols = OrderedDict() for col in metadata.c: name = str(col).rpartition(".")[2] cols[nam...
Check query sanity
def check_query(query): """ Check query sanity Args: query: query string Returns: None """ q = query.lower() if "select " not in q: raise InvalidQuery("SELECT word not found in the query: {0}".format(query)) if " from " not in q: raise InvalidQuery("FROM wor...
Extract columns names and python typos from query
def get_query_columns(engine, query): """ Extract columns names and python typos from query Args: engine: SQLAlchemy connection engine query: SQL query Returns: dict with columns names and python types """ con = engine.connect() result = con.execute(query).fetchone() ...
Check partition_column existence and type
def check_partition_column(partition_column, cols): """ Check partition_column existence and type Args: partition_column: partition_column name cols: dict with columns names and python types Returns: None """ for k, v in cols.items(): if k == partition_column: ...
Return a columns name list and the query string
def get_query_info(sql, con, partition_column): """ Return a columns name list and the query string Args: sql: SQL query or table name con: database connection or url string partition_column: column used to share the data between the workers Returns: Columns name list and q...
Put bounders in the query
def query_put_bounders(query, partition_column, start, end): """ Put bounders in the query Args: query: SQL query string partition_column: partition_column name start: lower_bound end: upper_bound Returns: Query with bounders """ where = " WHERE TMP_TABLE.{0...
Computes the index after a number of rows have been removed.
def compute_index(self, axis, data_object, compute_diff=True): """Computes the index after a number of rows have been removed. Note: In order for this to be used properly, the indexes must not be changed before you compute this. Args: axis: The axis to extract the index...
Prepares methods given various metadata. Args: pandas_func: The function to prepare.
def _prepare_method(self, pandas_func, **kwargs): """Prepares methods given various metadata. Args: pandas_func: The function to prepare. Returns Helper function which handles potential transpose. """ if self._is_transposed: def helper(df, in...
Returns the numeric columns of the Manager.
def numeric_columns(self, include_bool=True): """Returns the numeric columns of the Manager. Returns: List of index names. """ columns = [] for col, dtype in zip(self.columns, self.dtypes): if is_numeric_dtype(dtype) and ( include_bool or ...
Preprocesses numeric functions to clean dataframe and pick numeric indices.
def numeric_function_clean_dataframe(self, axis): """Preprocesses numeric functions to clean dataframe and pick numeric indices. Args: axis: '0' if columns and '1' if rows. Returns: Tuple with return value(if any), indices to apply func to & cleaned Manager. """...
Joins a pair of index objects ( columns or rows ) by a given strategy.
def _join_index_objects(self, axis, other_index, how, sort=True): """Joins a pair of index objects (columns or rows) by a given strategy. Args: axis: The axis index object to join (0 for columns, 1 for index). other_index: The other_index to join on. how: The type of...
Joins a list or two objects together.
def join(self, other, **kwargs): """Joins a list or two objects together. Args: other: The other object(s) to join on. Returns: Joined objects. """ if not isinstance(other, list): other = [other] return self._join_list_of_managers(oth...
Concatenates two objects together.
def concat(self, axis, other, **kwargs): """Concatenates two objects together. Args: axis: The axis index object to join (0 for columns, 1 for index). other: The other_index to concat with. Returns: Concatenated objects. """ return self._appe...
Copartition two QueryCompiler objects.
def copartition(self, axis, other, how_to_join, sort, force_repartition=False): """Copartition two QueryCompiler objects. Args: axis: The axis to copartition along. other: The other Query Compiler(s) to copartition against. how_to_join: How to manage joining the inde...
Converts Modin DataFrame to Pandas DataFrame.
def to_pandas(self): """Converts Modin DataFrame to Pandas DataFrame. Returns: Pandas DataFrame of the DataManager. """ df = self.data.to_pandas(is_transposed=self._is_transposed) if df.empty: if len(self.columns) != 0: df = pandas.DataFra...
Improve simple Pandas DataFrame to an advanced and superior Modin DataFrame.
def from_pandas(cls, df, block_partitions_cls): """Improve simple Pandas DataFrame to an advanced and superior Modin DataFrame. Args: cls: DataManger object to convert the DataFrame to. df: Pandas DataFrame object. block_partitions_cls: BlockParitions object to store...
Inter - data operations ( e. g. add sub ).
def _inter_manager_operations(self, other, how_to_join, func): """Inter-data operations (e.g. add, sub). Args: other: The other Manager for the operation. how_to_join: The type of join to join to make (e.g. right, outer). Returns: New DataManager with new da...
Helper method for inter - manager and scalar operations.
def _inter_df_op_handler(self, func, other, **kwargs): """Helper method for inter-manager and scalar operations. Args: func: The function to use on the Manager/scalar. other: The other Manager/scalar. Returns: New DataManager with new data and index. ...
Perform an operation between two objects.
def binary_op(self, op, other, **kwargs): """Perform an operation between two objects. Note: The list of operations is as follows: - add - eq - floordiv - ge - gt - le - lt - mod - mul ...
Uses other manager to update corresponding values in this manager.
def update(self, other, **kwargs): """Uses other manager to update corresponding values in this manager. Args: other: The other manager. Returns: New DataManager with updated data and index. """ assert isinstance( other, type(self) ),...
Gets values from this manager where cond is true else from other.
def where(self, cond, other, **kwargs): """Gets values from this manager where cond is true else from other. Args: cond: Condition on which to evaluate values. Returns: New DataManager with updated data and index. """ assert isinstance( cond...
Handler for mapping scalar operations across a Manager.
def _scalar_operations(self, axis, scalar, func): """Handler for mapping scalar operations across a Manager. Args: axis: The axis index object to execute the function on. scalar: The scalar value to map. func: The function to use on the Manager with the scalar. ...
Fits a new index for this Manger.
def reindex(self, axis, labels, **kwargs): """Fits a new index for this Manger. Args: axis: The axis index object to target the reindex on. labels: New labels to conform 'axis' on to. Returns: A new QueryCompiler with updated data and new index. """ ...
Removes all levels from index and sets a default level_0 index.
def reset_index(self, **kwargs): """Removes all levels from index and sets a default level_0 index. Returns: A new QueryCompiler with updated data and reset index. """ drop = kwargs.get("drop", False) new_index = pandas.RangeIndex(len(self.index)) if not drop...
Transposes this DataManager.
def transpose(self, *args, **kwargs): """Transposes this DataManager. Returns: Transposed new DataManager. """ new_data = self.data.transpose(*args, **kwargs) # Switch the index and columns and transpose the new_manager = self.__constructor__(new_data, self.c...
Apply function that will reduce the data to a Pandas Series.
def _full_reduce(self, axis, map_func, reduce_func=None): """Apply function that will reduce the data to a Pandas Series. Args: axis: 0 for columns and 1 for rows. Default is 0. map_func: Callable function to map the dataframe. reduce_func: Callable function to reduc...
Counts the number of non - NaN objects for each column or row.
def count(self, **kwargs): """Counts the number of non-NaN objects for each column or row. Return: A new QueryCompiler object containing counts of non-NaN objects from each column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis",...
Returns the mean for each numerical column or row.
def mean(self, **kwargs): """Returns the mean for each numerical column or row. Return: A new QueryCompiler object containing the mean from each numerical column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 ...
Returns the minimum from each column or row.
def min(self, **kwargs): """Returns the minimum from each column or row. Return: A new QueryCompiler object with the minimum value from each column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 return self.transpose()....
Calculates the sum or product of the DataFrame.
def _process_sum_prod(self, func, **kwargs): """Calculates the sum or product of the DataFrame. Args: func: Pandas func to apply to DataFrame. ignore_axis: Whether to ignore axis when raising TypeError Return: A new QueryCompiler object with sum or prod of th...
Returns the product of each numerical column or row.
def prod(self, **kwargs): """Returns the product of each numerical column or row. Return: A new QueryCompiler object with the product of each numerical column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 return self.t...
Calculates if any or all the values are true.
def _process_all_any(self, func, **kwargs): """Calculates if any or all the values are true. Return: A new QueryCompiler object containing boolean values or boolean. """ axis = kwargs.get("axis", 0) axis = 0 if axis is None else axis kwargs["axis"] = axis ...
Returns whether all the elements are true potentially over an axis.
def all(self, **kwargs): """Returns whether all the elements are true, potentially over an axis. Return: A new QueryCompiler object containing boolean values or boolean. """ if self._is_transposed: # Pandas ignores on axis=1 kwargs["bool_only"] = Fals...
Converts columns dtypes to given dtypes.
def astype(self, col_dtypes, **kwargs): """Converts columns dtypes to given dtypes. Args: col_dtypes: Dictionary of {col: dtype,...} where col is the column name and dtype is a numpy dtype. Returns: DataFrame with updated dtypes. """ # Gr...
Applies map that reduce Manager to series but require knowledge of full axis.
def _full_axis_reduce(self, axis, func, alternate_index=None): """Applies map that reduce Manager to series but require knowledge of full axis. Args: func: Function to reduce the Manager by. This function takes in a Manager. axis: axis to apply the function to. alter...
Returns index of first non - NaN/ NULL value.
def first_valid_index(self): """Returns index of first non-NaN/NULL value. Return: Scalar of index name. """ # It may be possible to incrementally check each partition, but this # computation is fairly cheap. def first_valid_index_builder(df): df....
Returns the first occurrence of the maximum over requested axis.
def idxmax(self, **kwargs): """Returns the first occurrence of the maximum over requested axis. Returns: A new QueryCompiler object containing the maximum of each column or axis. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 r...
Returns the first occurrence of the minimum over requested axis.
def idxmin(self, **kwargs): """Returns the first occurrence of the minimum over requested axis. Returns: A new QueryCompiler object containing the minimum of each column or axis. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 r...
Returns index of last non - NaN/ NULL value.
def last_valid_index(self): """Returns index of last non-NaN/NULL value. Return: Scalar of index name. """ def last_valid_index_builder(df): df.index = pandas.RangeIndex(len(df.index)) return df.apply(lambda df: df.last_valid_index()) func =...
Returns median of each column or row.
def median(self, **kwargs): """Returns median of each column or row. Returns: A new QueryCompiler object containing the median of each column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 return self.transpose().median...
Returns the memory usage of each column.
def memory_usage(self, **kwargs): """Returns the memory usage of each column. Returns: A new QueryCompiler object containing the memory usage of each column. """ def memory_usage_builder(df, **kwargs): return df.memory_usage(**kwargs) func = self._build...
Returns quantile of each column or row.
def quantile_for_single_value(self, **kwargs): """Returns quantile of each column or row. Returns: A new QueryCompiler object containing the quantile of each column or row. """ if self._is_transposed: kwargs["axis"] = kwargs.get("axis", 0) ^ 1 return ...
Reduce Manger along select indices using function that needs full axis.
def _full_axis_reduce_along_select_indices(self, func, axis, index): """Reduce Manger along select indices using function that needs full axis. Args: func: Callable that reduces the dimension of the object and requires full knowledge of the entire axis. axis: 0 f...
Generates descriptive statistics.
def describe(self, **kwargs): """Generates descriptive statistics. Returns: DataFrame object containing the descriptive statistics of the DataFrame. """ # Use pandas to calculate the correct columns new_columns = ( pandas.DataFrame(columns=self.columns) ...
Returns a new QueryCompiler with null values dropped along given axis. Return: a new DataManager
def dropna(self, **kwargs): """Returns a new QueryCompiler with null values dropped along given axis. Return: a new DataManager """ axis = kwargs.get("axis", 0) subset = kwargs.get("subset", None) thresh = kwargs.get("thresh", None) how = kwargs.get("h...
Returns a new QueryCompiler with expr evaluated on columns.
def eval(self, expr, **kwargs): """Returns a new QueryCompiler with expr evaluated on columns. Args: expr: The string expression to evaluate. Returns: A new QueryCompiler with new columns after applying expr. """ columns = self.index if self._is_transpos...
Returns a new QueryCompiler with modes calculated for each label along given axis.
def mode(self, **kwargs): """Returns a new QueryCompiler with modes calculated for each label along given axis. Returns: A new QueryCompiler with modes calculated. """ axis = kwargs.get("axis", 0) def mode_builder(df, **kwargs): result = df.mode(**kwargs...
Replaces NaN values with the method provided.
def fillna(self, **kwargs): """Replaces NaN values with the method provided. Returns: A new QueryCompiler with null values filled. """ axis = kwargs.get("axis", 0) value = kwargs.get("value") if isinstance(value, dict): value = kwargs.pop("value")...
Query columns of the DataManager with a boolean expression.
def query(self, expr, **kwargs): """Query columns of the DataManager with a boolean expression. Args: expr: Boolean expression to query the columns with. Returns: DataManager containing the rows where the boolean expression is satisfied. """ columns = se...
Computes numerical rank along axis. Equal values are set to the average.
def rank(self, **kwargs): """Computes numerical rank along axis. Equal values are set to the average. Returns: DataManager containing the ranks of the values along an axis. """ axis = kwargs.get("axis", 0) numeric_only = True if axis else kwargs.get("numeric_only", F...
Sorts the data with respect to either the columns or the indices.
def sort_index(self, **kwargs): """Sorts the data with respect to either the columns or the indices. Returns: DataManager containing the data sorted by columns or indices. """ axis = kwargs.pop("axis", 0) index = self.columns if axis else self.index # sort_i...
Maps function to select indices along full axis.
def _map_across_full_axis_select_indices( self, axis, func, indices, keep_remaining=False ): """Maps function to select indices along full axis. Args: axis: 0 for columns and 1 for rows. func: Callable mapping function over the BlockParitions. indices: in...
Returns Manager containing quantiles along an axis for numeric columns.
def quantile_for_list_of_values(self, **kwargs): """Returns Manager containing quantiles along an axis for numeric columns. Returns: DataManager containing quantiles of original DataManager along an axis. """ if self._is_transposed: kwargs["axis"] = kwargs.get("a...
Returns the last n rows.
def tail(self, n): """Returns the last n rows. Args: n: Integer containing the number of rows to return. Returns: DataManager containing the last n rows of the original DataManager. """ # See head for an explanation of the transposed behavior if ...
Returns the first n columns.
def front(self, n): """Returns the first n columns. Args: n: Integer containing the number of columns to return. Returns: DataManager containing the first n columns of the original DataManager. """ new_dtypes = ( self._dtype_cache if self._dt...
Get column data for target labels.
def getitem_column_array(self, key): """Get column data for target labels. Args: key: Target labels by which to retrieve data. Returns: A new QueryCompiler. """ # Convert to list for type checking numeric_indices = list(self.columns.get_indexer_f...
Get row data for target labels.
def getitem_row_array(self, key): """Get row data for target labels. Args: key: Target numeric indices by which to retrieve data. Returns: A new QueryCompiler. """ # Convert to list for type checking key = list(key) def getitem(df, inter...
Set the column defined by key to the value provided.
def setitem(self, axis, key, value): """Set the column defined by `key` to the `value` provided. Args: key: The column name to set. value: The value to set the column to. Returns: A new QueryCompiler """ def setitem(df, internal_indices=[])...
Remove row data for target index and columns.
def drop(self, index=None, columns=None): """Remove row data for target index and columns. Args: index: Target index to drop. columns: Target columns to drop. Returns: A new QueryCompiler. """ if self._is_transposed: return self.t...
Insert new column data.
def insert(self, loc, column, value): """Insert new column data. Args: loc: Insertion index. column: Column labels to insert. value: Dtype object values to insert. Returns: A new PandasQueryCompiler with new data inserted. """ if ...
Apply func across given axis.
def apply(self, func, axis, *args, **kwargs): """Apply func across given axis. Args: func: The function to apply. axis: Target axis to apply the function along. Returns: A new PandasQueryCompiler. """ if callable(func): return sel...
Recompute the index after applying function.
def _post_process_apply(self, result_data, axis, try_scale=True): """Recompute the index after applying function. Args: result_data: a BaseFrameManager object. axis: Target axis along which function was applied. Returns: A new PandasQueryCompiler. ""...
Apply function to certain indices across given axis.
def _dict_func(self, func, axis, *args, **kwargs): """Apply function to certain indices across given axis. Args: func: The function to apply. axis: Target axis to apply the function along. Returns: A new PandasQueryCompiler. """ if "axis" not...
Apply list - like function across given axis.
def _list_like_func(self, func, axis, *args, **kwargs): """Apply list-like function across given axis. Args: func: The function to apply. axis: Target axis to apply the function along. Returns: A new PandasQueryCompiler. """ func_prepared = s...
Apply callable functions across given axis.
def _callable_func(self, func, axis, *args, **kwargs): """Apply callable functions across given axis. Args: func: The functions to apply. axis: Target axis to apply the function along. Returns: A new PandasQueryCompiler. """ def callable_app...
This method applies all manual partitioning functions.
def _manual_repartition(self, axis, repartition_func, **kwargs): """This method applies all manual partitioning functions. Args: axis: The axis to shuffle data along. repartition_func: The function used to repartition data. Returns: A `BaseFrameManager` obje...
Convert categorical variables to dummy variables for certain columns.
def get_dummies(self, columns, **kwargs): """Convert categorical variables to dummy variables for certain columns. Args: columns: The columns to convert. Returns: A new QueryCompiler. """ cls = type(self) # `columns` as None does not mean all col...
Note: this function involves making copies of the index in memory.
def global_idx_to_numeric_idx(self, axis, indices): """ Note: this function involves making copies of the index in memory. Args: axis: Axis to extract indices. indices: Indices to convert to numerical. Returns: An Index object. """ as...
Perform the map step
def _get_data(self) -> BaseFrameManager: """Perform the map step Returns: A BaseFrameManager object. """ def iloc(partition, row_internal_indices, col_internal_indices): return partition.iloc[row_internal_indices, col_internal_indices] masked_data = sel...
Gets the lengths of the blocks.
def block_lengths(self): """Gets the lengths of the blocks. Note: This works with the property structure `_lengths_cache` to avoid having to recompute these values each time they are needed. """ if self._lengths_cache is None: # The first column will have the cor...
Gets the widths of the blocks.
def block_widths(self): """Gets the widths of the blocks. Note: This works with the property structure `_widths_cache` to avoid having to recompute these values each time they are needed. """ if self._widths_cache is None: # The first column will have the correct...
Updates the current DataFrame inplace. Args: new_query_compiler: The new QueryCompiler to use to manage the data
def _update_inplace(self, new_query_compiler): """Updates the current DataFrame inplace. Args: new_query_compiler: The new QueryCompiler to use to manage the data """ old_query_compiler = self._query_compiler self._query_compiler = new_query_compiler ...
Helper method to check validity of other in inter - df operations
def _validate_other( self, other, axis, numeric_only=False, numeric_or_time_only=False, numeric_or_object_only=False, comparison_dtypes_only=False, ): """Helper method to check validity of other in inter-df operations""" axis = self._...
Helper method to use default pandas function
def _default_to_pandas(self, op, *args, **kwargs): """Helper method to use default pandas function""" empty_self_str = "" if not self.empty else " for empty DataFrame" ErrorMessage.default_to_pandas( "`{}.{}`{}".format( self.__name__, op if isins...
Apply an absolute value function to all numeric columns. Returns: A new DataFrame with the applied absolute value.
def abs(self): """Apply an absolute value function to all numeric columns. Returns: A new DataFrame with the applied absolute value. """ self._validate_dtypes(numeric_only=True) return self.__constructor__(query_compiler=self._query_compiler.abs())
Add this DataFrame to another or a scalar/ list. Args: other: What to add this this DataFrame. axis: The axis to apply addition over. Only applicaable to Series or list other. level: A level in the multilevel axis to add over. fill_value: The value to fill NaN. Returns: A new DataFrame with the applied addition.
def add(self, other, axis="columns", level=None, fill_value=None): """Add this DataFrame to another or a scalar/list. Args: other: What to add this this DataFrame. axis: The axis to apply addition over. Only applicaable to Series or list 'other'. ...
Return whether all elements are True over requested axis Note: If axis = None or axis = 0 this call applies df. all ( axis = 1 ) to the transpose of df.
def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): """Return whether all elements are True over requested axis Note: If axis=None or axis=0, this call applies df.all(axis=1) to the transpose of df. """ if axis is not None: ...
Apply a function along input axis of DataFrame. Args: func: The function to apply axis: The axis over which to apply the func. broadcast: Whether or not to broadcast. raw: Whether or not to convert to a Series. reduce: Whether or not to try to apply reduction procedures. Returns: Series or DataFrame depending on func.
def apply( self, func, axis=0, broadcast=None, raw=False, reduce=None, result_type=None, convert_dtype=True, args=(), **kwds ): """Apply a function along input axis of DataFrame. Args: func: T...
Synonym for DataFrame. fillna ( method = bfill )
def bfill(self, axis=None, inplace=False, limit=None, downcast=None): """Synonym for DataFrame.fillna(method='bfill')""" return self.fillna( method="bfill", axis=axis, limit=limit, downcast=downcast, inplace=inplace )
Return the bool of a single element PandasObject. This must be a boolean scalar value either True or False. Raise a ValueError if the PandasObject does not have exactly 1 element or that element is not boolean
def bool(self): """Return the bool of a single element PandasObject. This must be a boolean scalar value, either True or False. Raise a ValueError if the PandasObject does not have exactly 1 element, or that element is not boolean """ shape = self.shape ...
Creates a shallow copy of the DataFrame. Returns: A new DataFrame pointing to the same partitions as this one.
def copy(self, deep=True): """Creates a shallow copy of the DataFrame. Returns: A new DataFrame pointing to the same partitions as this one. """ return self.__constructor__(query_compiler=self._query_compiler.copy())
Get the count of non - null objects in the DataFrame. Arguments: axis: 0 or index for row - wise 1 or columns for column - wise. level: If the axis is a MultiIndex ( hierarchical ) count along a particular level collapsing into a DataFrame. numeric_only: Include only float int boolean data Returns: The count in a Serie...
def count(self, axis=0, level=None, numeric_only=False): """Get the count of non-null objects in the DataFrame. Arguments: axis: 0 or 'index' for row-wise, 1 or 'columns' for column-wise. level: If the axis is a MultiIndex (hierarchical), count along a part...
Perform a cumulative maximum across the DataFrame. Args: axis ( int ): The axis to take maximum on. skipna ( bool ): True to skip NA values false otherwise. Returns: The cumulative maximum of the DataFrame.
def cummax(self, axis=None, skipna=True, *args, **kwargs): """Perform a cumulative maximum across the DataFrame. Args: axis (int): The axis to take maximum on. skipna (bool): True to skip NA values, false otherwise. Returns: The cumulative maximum of...
Perform a cumulative product across the DataFrame. Args: axis ( int ): The axis to take product on. skipna ( bool ): True to skip NA values false otherwise. Returns: The cumulative product of the DataFrame.
def cumprod(self, axis=None, skipna=True, *args, **kwargs): """Perform a cumulative product across the DataFrame. Args: axis (int): The axis to take product on. skipna (bool): True to skip NA values, false otherwise. Returns: The cumulative product o...
Generates descriptive statistics that summarize the central tendency dispersion and shape of a dataset s distribution excluding NaN values. Args: percentiles ( list - like of numbers optional ): The percentiles to include in the output. include: White - list of data types to include in results exclude: Black - list of ...
def describe(self, percentiles=None, include=None, exclude=None): """ Generates descriptive statistics that summarize the central tendency, dispersion and shape of a dataset's distribution, excluding NaN values. Args: percentiles (list-like of numbers, optional): ...
Finds the difference between elements on the axis requested Args: periods: Periods to shift for forming difference axis: Take difference over rows or columns Returns: DataFrame with the diff applied
def diff(self, periods=1, axis=0): """Finds the difference between elements on the axis requested Args: periods: Periods to shift for forming difference axis: Take difference over rows or columns Returns: DataFrame with the diff applied """ ...
Return new object with labels in requested axis removed. Args: labels: Index or column labels to drop. axis: Whether to drop labels from the index ( 0/ index ) or columns ( 1/ columns ). index columns: Alternative to specifying axis ( labels axis = 1 is equivalent to columns = labels ). level: For MultiIndex inplace: I...
def drop( self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors="raise", ): """Return new object with labels in requested axis removed. Args: labels: Index or column labels to dro...
Create a new DataFrame from the removed NA values from this one. Args: axis ( int tuple or list ): The axis to apply the drop. how ( str ): How to drop the NA values. all: drop the label if all values are NA. any: drop the label if any values are NA. thresh ( int ): The minimum number of NAs to require. subset ( [ labe...
def dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False): """Create a new DataFrame from the removed NA values from this one. Args: axis (int, tuple, or list): The axis to apply the drop. how (str): How to drop the NA values. 'all': drop...
Return DataFrame with duplicate rows removed optionally only considering certain columns Args: subset: column label or sequence of labels optional Only consider certain columns for identifying duplicates by default use all of the columns keep: { first last False } default first - first: Drop duplicates except for the f...
def drop_duplicates(self, keep="first", inplace=False, **kwargs): """Return DataFrame with duplicate rows removed, optionally only considering certain columns Args: subset : column label or sequence of labels, optional Only consider certain columns for ident...
Checks element - wise that this is equal to other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the eq over. level: The Multilevel index level to apply eq over. Returns: A new DataFrame filled with Booleans.
def eq(self, other, axis="columns", level=None): """Checks element-wise that this is equal to other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the eq over. level: The Multilevel index level to apply eq over. ...
Fill NA/ NaN values using the specified method. Args: value: Value to use to fill holes. This value cannot be a list. method: Method to use for filling holes in reindexed Series pad. ffill: propagate last valid observation forward to next valid backfill. bfill: use NEXT valid observation to fill gap. axis: 0 or index 1...
def fillna( self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs ): """Fill NA/NaN values using the specified method. Args: value: Value to use to fill holes. This value ...
Subset rows or columns based on their labels Args: items ( list ): list of labels to subset like ( string ): retain labels where arg in label == True regex ( string ): retain labels matching regex input axis: axis to filter on Returns: A new DataFrame with the filter applied.
def filter(self, items=None, like=None, regex=None, axis=None): """Subset rows or columns based on their labels Args: items (list): list of labels to subset like (string): retain labels where `arg in label == True` regex (string): retain labels matching regex i...
Divides this DataFrame against another DataFrame/ Series/ scalar. Args: other: The object to use to apply the divide against this. axis: The axis to divide over. level: The Multilevel index level to apply divide over. fill_value: The value to fill NaNs with. Returns: A new DataFrame with the Divide applied.
def floordiv(self, other, axis="columns", level=None, fill_value=None): """Divides this DataFrame against another DataFrame/Series/scalar. Args: other: The object to use to apply the divide against this. axis: The axis to divide over. level: The Multilevel inde...
Checks element - wise that this is greater than or equal to other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the gt over. level: The Multilevel index level to apply gt over. Returns: A new DataFrame filled with Booleans.
def ge(self, other, axis="columns", level=None): """Checks element-wise that this is greater than or equal to other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the gt over. level: The Multilevel index level to apply gt...
Get the counts of dtypes in this object. Returns: The counts of dtypes in this object.
def get_dtype_counts(self): """Get the counts of dtypes in this object. Returns: The counts of dtypes in this object. """ if hasattr(self, "dtype"): return pandas.Series({str(self.dtype): 1}) result = self.dtypes.value_counts() result.ind...
Get the counts of ftypes in this object. Returns: The counts of ftypes in this object.
def get_ftype_counts(self): """Get the counts of ftypes in this object. Returns: The counts of ftypes in this object. """ if hasattr(self, "ftype"): return pandas.Series({self.ftype: 1}) return self.ftypes.value_counts().sort_index()
Checks element - wise that this is greater than other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the gt over. level: The Multilevel index level to apply gt over. Returns: A new DataFrame filled with Booleans.
def gt(self, other, axis="columns", level=None): """Checks element-wise that this is greater than other. Args: other: A DataFrame or Series or scalar to compare to. axis: The axis to perform the gt over. level: The Multilevel index level to apply gt over. ...
Get the first n rows of the DataFrame. Args: n ( int ): The number of rows to return. Returns: A new DataFrame with the first n rows of the DataFrame.
def head(self, n=5): """Get the first n rows of the DataFrame. Args: n (int): The number of rows to return. Returns: A new DataFrame with the first n rows of the DataFrame. """ if n >= len(self.index): return self.copy() re...
Get the index of the first occurrence of the max value of the axis. Args: axis ( int ): Identify the max over the rows ( 1 ) or columns ( 0 ). skipna ( bool ): Whether or not to skip NA values. Returns: A Series with the index for each maximum value for the axis specified.
def idxmax(self, axis=0, skipna=True, *args, **kwargs): """Get the index of the first occurrence of the max value of the axis. Args: axis (int): Identify the max over the rows (1) or columns (0). skipna (bool): Whether or not to skip NA values. Returns: ...
Fill a DataFrame with booleans for cells contained in values. Args: values ( iterable DataFrame Series or dict ): The values to find. Returns: A new DataFrame with booleans representing whether or not a cell is in values. True: cell is contained in values. False: otherwise
def isin(self, values): """Fill a DataFrame with booleans for cells contained in values. Args: values (iterable, DataFrame, Series, or dict): The values to find. Returns: A new DataFrame with booleans representing whether or not a cell is in values. ...