MCPcopy
hub / github.com/pandas-dev/pandas / drop

Method drop

pandas/core/indexes/base.py:7222–7270  ·  view source on GitHub ↗

Make new Index with passed list of labels deleted. Parameters ---------- labels : array-like or scalar Array-like object or a scalar value, representing the labels to be removed from the Index. errors : {'ignore', 'raise'}, default 'r

(
        self,
        labels: Index | np.ndarray | Iterable[Hashable],
        errors: IgnoreRaise = "raise",
    )

Source from the content-addressed store, hash-verified

7220 return out
7221
7222 def drop(
7223 self,
7224 labels: Index | np.ndarray | Iterable[Hashable],
7225 errors: IgnoreRaise = "raise",
7226 ) -> Index:
7227 """
7228 Make new Index with passed list of labels deleted.
7229
7230 Parameters
7231 ----------
7232 labels : array-like or scalar
7233 Array-like object or a scalar value, representing the labels to be removed
7234 from the Index.
7235 errors : {'ignore', 'raise'}, default 'raise'
7236 If 'ignore', suppress error and existing labels are dropped.
7237
7238 Returns
7239 -------
7240 Index
7241 Will be same type as self, except for RangeIndex.
7242
7243 Raises
7244 ------
7245 KeyError
7246 If not all of the labels are found in the selected axis
7247
7248 See Also
7249 --------
7250 Index.dropna : Return Index without NA/NaN values.
7251 Index.drop_duplicates : Return Index with duplicate values removed.
7252
7253 Examples
7254 --------
7255 >>> idx = pd.Index(["a", "b", "c"])
7256 >>> idx.drop(["a"])
7257 Index(['b', 'c'], dtype='str')
7258 """
7259 if not isinstance(labels, Index):
7260 # avoid materializing e.g. RangeIndex
7261 arr_dtype = "object" if self.dtype == "object" else None
7262 labels = com.index_labels_to_array(labels, dtype=arr_dtype)
7263
7264 indexer = self.get_indexer_for(labels)
7265 mask = indexer == -1
7266 if mask.any():
7267 if errors != "ignore":
7268 raise KeyError(f"{labels[mask].tolist()} not found in axis")
7269 indexer = indexer[~mask]
7270 return self.delete(indexer)
7271
7272 @final
7273 def infer_objects(self, copy: bool = True) -> Index:

Callers 11

test_drop_tupleMethod · 0.95
__init__Method · 0.45
_applyMethod · 0.45
_apply_pairwiseMethod · 0.45
get_dummiesFunction · 0.45
__internal_pivot_tableFunction · 0.45
_indicator_post_mergeMethod · 0.45
computeMethod · 0.45

Calls 4

get_indexer_forMethod · 0.95
deleteMethod · 0.95
anyMethod · 0.45
tolistMethod · 0.45