mteb/BrightProStackoverflowRetrieval huggingface dataset:
y.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.median  #

DataFrame.  median  (  _ axis  =  0  _ , _ skipna  =  True  _ , _ numeric_only
=  False  _ , _ **  kwargs  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L11698-L11709) #

    

Return the median of the values over the requested axis.

Parameters  :

    

**axis** {index (0), columns (1)}

    

Axis for the function to be applied on. For  Series  this parameter is unused
and defaults to 0.

For DataFrames, specifying ` axis=None  ` will apply the aggregation across
both axes.

New in version 2.0.0.

**skipna** bool, default True

    

Exclude NA/null values when computing the result.

**numeric_only** bool, default False

    

Include only float, int, boolean columns. Not implemented for Series.

****kwargs**

    

Additional keyword arguments to be passed to the function.

Returns  :

    

Series or scalar

    

Examples

    
    
    >>> s = pd.Series([1, 2, 3])
    >>> s.median()
    2.0
    

With a DataFrame

    
    
    >>> df = pd.DataFrame({'a': [1, 2], 'b': [2, 3]}, index=['tiger', 'zebra'])
    >>> df
           a   b
    tiger  1   2
    zebra  2   3
    >>> df.median()
    a   1.5
    b   2.5
    dtype: float64
    

Using axis=1

    
    
    >>> df.median(axis=1)
    tiger   1.5
    zebra   2.5
    dtype: float64
    

In this case,  numeric_only  should be set to  True  to avoid getting an
error.

    
    
    >>> df = pd.DataFrame({'a': [1, 2], 'b': ['T', 'Z']},
    ...                   index=['tiger', 'zebra'])
    >>> df.median(numeric_only=True)
    a   1.5
    dtype: float64
    

[ __ previous  pandas.DataFrame.mean  ](pandas.DataFrame.mean.html "previous
page") [ next  pandas.DataFrame.min  __ ](pandas.DataFrame.min.html "next
page")

__ On this page

  * ` DataFrame.median()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.median.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
dinals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.PeriodIndex ](pandas.PeriodIndex.html)
  * pandas.Perio... 

#  pandas.PeriodIndex.day_of_week  #

_ property  _ PeriodIndex.  day_of_week  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/extension.py#L67-L75) #

    

The day of the week with Monday=0, Sunday=6.

Examples

    
    
    >>> idx = pd.PeriodIndex(["2023-01-01", "2023-01-02", "2023-01-03"], freq="D")
    >>> idx.weekday
    Index([6, 0, 1], dtype='int64')
    

[ __ previous  pandas.PeriodIndex.dayofweek
](pandas.PeriodIndex.dayofweek.html "previous page") [ next
pandas.PeriodIndex.dayofyear  __ ](pandas.PeriodIndex.dayofyear.html "next
page")

__ On this page

  * ` PeriodIndex.day_of_week  `

[ __ Show Source
](../../_sources/reference/api/pandas.PeriodIndex.day_of_week.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.swapaxes  #

DataFrame.  swapaxes  (  _ axis1  _ , _ axis2  _ , _ copy  =  None  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/generic.py#L817-L879) #

    

Interchange axes and swap values axes appropriately.

Deprecated since version 2.1.0:  ` swapaxes  ` is deprecated and will be
removed. Please use ` transpose  ` instead.

Returns  :

    

same as input

    

Examples

Please see examples for [ ` DataFrame.transpose()  `
](pandas.DataFrame.transpose.html#pandas.DataFrame.transpose
"pandas.DataFrame.transpose") .

[ __ previous  pandas.DataFrame.unstack  ](pandas.DataFrame.unstack.html
"previous page") [ next  pandas.DataFrame.melt  __
](pandas.DataFrame.melt.html "next page")

__ On this page

  * ` DataFrame.swapaxes()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.swapaxes.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
nals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.PeriodIndex ](pandas.PeriodIndex.html)
  * pandas.Perio... 

#  pandas.PeriodIndex.to_timestamp  #

PeriodIndex.  to_timestamp  (  _ freq  =  None  _ , _ how  =  'start'  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/period.py#L211-L214) #

    

Cast to DatetimeArray/Index.

Parameters  :

    

**freq** str or DateOffset, optional

    

Target frequency. The default is âDâ for week or longer, âsâ
otherwise.

**how** {âsâ, âeâ, âstartâ, âendâ}

    

Whether to use the start or end of the time period being converted.

Returns  :

    

DatetimeArray/Index

    

Examples

    
    
    >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
    >>> idx.to_timestamp()
    DatetimeIndex(['2023-01-01', '2023-02-01', '2023-03-01'],
    dtype='datetime64[ns]', freq='MS')
    

[ __ previous  pandas.PeriodIndex.strftime  ](pandas.PeriodIndex.strftime.html
"previous page") [ next  pandas.PeriodIndex.freq  __
](pandas.PeriodIndex.freq.html "next page")

__ On this page

  * ` PeriodIndex.to_timestamp()  `

[ __ Show Source
](../../_sources/reference/api/pandas.PeriodIndex.to_timestamp.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.unstack  #

DataFrame.  unstack  (  _ level  =  -1  _ , _ fill_value  =  None  _ , _ sort
=  True  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L9863-L9930) #

    

Pivot a level of the (necessarily hierarchical) index labels.

Returns a DataFrame having a new level of column labels whose inner-most level
consists of the pivoted index labels.

If the index is not a MultiIndex, the output will be a Series (the analogue of
stack when the columns are not a MultiIndex).

Parameters  :

    

**level** int, str, or list of these, default -1 (last level)

    

Level(s) of index to unstack, can pass level name.

**fill_value** int, str or dict

    

Replace NaN with this value if the unstack produces missing values.

**sort** bool, default True

    

Sort the level(s) in the resulting MultiIndex columns.

Returns  :

    

Series or DataFrame

    

See also

[ ` DataFrame.pivot  ` ](pandas.DataFrame.pivot.html#pandas.DataFrame.pivot
"pandas.DataFrame.pivot")

    

Pivot a table based on column values.

[ ` DataFrame.stack  ` ](pandas.DataFrame.stack.html#pandas.DataFrame.stack
"pandas.DataFrame.stack")

    

Pivot a level of the column labels (inverse operation from  unstack  ).

Notes

Reference [ the user guide  ](../../user_guide/reshaping.html#reshaping-
stacking) for more examples.

Examples

    
    
    >>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),
    ...                                    ('two', 'a'), ('two', 'b')])
    >>> s = pd.Series(np.arange(1.0, 5.0), index=index)
    >>> s
    one  a   1.0
         b   2.0
    two  a   3.0
         b   4.0
    dtype: float64
    
    
    
    >>> s.unstack(level=-1)
         a   b
    one  1.0  2.0
    two  3.0  4.0
    
    
    
    >>> s.unstack(level=0)
       one  two
    a  1.0   3.0
    b  2.0   4.0
    
    
    
    >>> df = s.unstack(level=0)
    >>> df.unstack()
    one  a  1.0
         b  2.0
    two  a  3.0
         b  4.0
    dtype: float64
    

[ __ previous  pandas.DataFrame.stack  ](pandas.DataFrame.stack.html "previous
page") [ next  pandas.DataFrame.swapaxes  __ ](pandas.DataFrame.swapaxes.html
"next page")

__ On this page

  * ` DataFrame.unstack()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.unstack.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
ex.from_ordinals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.PeriodIndex ](pandas.PeriodIndex.html)
  * pandas.Perio... 

#  pandas.PeriodIndex.minute  #

_ property  _ PeriodIndex.  minute  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/extension.py#L67-L75) #

    

The minute of the period.

Examples

    
    
    >>> idx = pd.PeriodIndex(["2023-01-01 10:30:00",
    ...                       "2023-01-01 11:50:00"], freq='min')
    >>> idx.minute
    Index([30, 50], dtype='int64')
    

[ __ previous  pandas.PeriodIndex.is_leap_year
](pandas.PeriodIndex.is_leap_year.html "previous page") [ next
pandas.PeriodIndex.month  __ ](pandas.PeriodIndex.month.html "next page")

__ On this page

  * ` PeriodIndex.minute  `

[ __ Show Source
](../../_sources/reference/api/pandas.PeriodIndex.minute.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
dinals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.PeriodIndex ](pandas.PeriodIndex.html)
  * pandas.Perio... 

#  pandas.PeriodIndex.day_of_year  #

_ property  _ PeriodIndex.  day_of_year  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/extension.py#L67-L75) #

    

The ordinal day of the year.

Examples

    
    
    >>> idx = pd.PeriodIndex(["2023-01-10", "2023-02-01", "2023-03-01"], freq="D")
    >>> idx.dayofyear
    Index([10, 32, 60], dtype='int64')
    
    
    
    >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
    >>> idx
    PeriodIndex(['2023', '2024', '2025'], dtype='period[Y-DEC]')
    >>> idx.dayofyear
    Index([365, 366, 365], dtype='int64')
    

[ __ previous  pandas.PeriodIndex.dayofyear
](pandas.PeriodIndex.dayofyear.html "previous page") [ next
pandas.PeriodIndex.days_in_month  __ ](pandas.PeriodIndex.days_in_month.html
"next page")

__ On this page

  * ` PeriodIndex.day_of_year  `

[ __ Show Source
](../../_sources/reference/api/pandas.PeriodIndex.day_of_year.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.backfill  #

DataFrame.  backfill  (  _ *  _ , _ axis  =  None  _ , _ inplace  =  False  _
, _ limit  =  None  _ , _ downcast  =  _NoDefault.no_default  _ )  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/generic.py#L7812-L7844) #

    

Fill NA/NaN values by using the next valid observation to fill the gap.

Deprecated since version 2.0:  Series/DataFrame.backfill is deprecated. Use
Series/DataFrame.bfill instead.

Returns  :

    

Series/DataFrame or None

    

Object with missing values filled or None if ` inplace=True  ` .

Examples

Please see examples for [ ` DataFrame.bfill()  `
](pandas.DataFrame.bfill.html#pandas.DataFrame.bfill "pandas.DataFrame.bfill")
or [ ` Series.bfill()  ` ](pandas.Series.bfill.html#pandas.Series.bfill
"pandas.Series.bfill") .

[ __ previous  pandas.DataFrame.truncate  ](pandas.DataFrame.truncate.html
"previous page") [ next  pandas.DataFrame.bfill  __
](pandas.DataFrame.bfill.html "next page")

__ On this page

  * ` DataFrame.backfill()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.backfill.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
* [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.reorder_levels  #

DataFrame.  reorder_levels  (  _ order  _ , _ axis  =  0  _ )  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L7836-L7889) #

    

Rearrange index levels using input order. May not drop or duplicate levels.

Parameters  :

    

**order** list of int or list of str

    

List representing new level order. Reference level by number (position) or by
key (label).

**axis** {0 or âindexâ, 1 or âcolumnsâ}, default 0

    

Where to reorder levels.

Returns  :

    

DataFrame

    

Examples

    
    
    >>> data = {
    ...     "class": ["Mammals", "Mammals", "Reptiles"],
    ...     "diet": ["Omnivore", "Carnivore", "Carnivore"],
    ...     "species": ["Humans", "Dogs", "Snakes"],
    ... }
    >>> df = pd.DataFrame(data, columns=["class", "diet", "species"])
    >>> df = df.set_index(["class", "diet"])
    >>> df
                                      species
    class      diet
    Mammals    Omnivore                Humans
               Carnivore                 Dogs
    Reptiles   Carnivore               Snakes
    

Letâs reorder the levels of the index:

    
    
    >>> df.reorder_levels(["diet", "class"])
                                      species
    diet      class
    Omnivore  Mammals                  Humans
    Carnivore Mammals                    Dogs
              Reptiles                 Snakes
    

[ __ previous  pandas.DataFrame.pivot_table
](pandas.DataFrame.pivot_table.html "previous page") [ next
pandas.DataFrame.sort_values  __ ](pandas.DataFrame.sort_values.html "next
page")

__ On this page

  * ` DataFrame.reorder_levels()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.reorder_levels.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
by.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.first  #

DataFrame.  first  (  _ offset  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/generic.py#L9786-L9867) #

    

Select initial periods of time series data based on a date offset.

Deprecated since version 2.1:  ` first()  ` is deprecated and will be removed
in a future version. Please create a mask and filter using  .loc  instead.

For a DataFrame with a sorted DatetimeIndex, this function can select the
first few rows based on a date offset.

Parameters  :

    

**offset** str, DateOffset or dateutil.relativedelta

    

The offset length of the data that will be selected. For instance, â1MEâ
will display all the rows having their index within the first month.

Returns  :

    

Series or DataFrame

    

A subset of the caller.

Raises  :

    

TypeError

    

If the index is not a [ ` DatetimeIndex  `
](pandas.DatetimeIndex.html#pandas.DatetimeIndex "pandas.DatetimeIndex")

See also

[ ` last  ` ](pandas.DataFrame.last.html#pandas.DataFrame.last
"pandas.DataFrame.last")

    

Select final periods of time series based on a date offset.

[ ` at_time  ` ](pandas.DataFrame.at_time.html#pandas.DataFrame.at_time
"pandas.DataFrame.at_time")

    

Select values at a particular time of the day.

[ ` between_time  `
](pandas.DataFrame.between_time.html#pandas.DataFrame.between_time
"pandas.DataFrame.between_time")

    

Select values between particular times of the day.

Examples

    
    
    >>> i = pd.date_range('2018-04-09', periods=4, freq='2D')
    >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i)
    >>> ts
                A
    2018-04-09  1
    2018-04-11  2
    2018-04-13  3
    2018-04-15  4
    

Get the rows for the first 3 days:

    
    
    >>> ts.first('3D')
                A
    2018-04-09  1
    2018-04-11  2
    

Notice the data for 3 first calendar days were returned, not the first 3 days
observed in the dataset, and therefore data for 2018-04-13 was not returned.

[ __ previous  pandas.DataFrame.filter  ](pandas.DataFrame.filter.html
"previous page") [ next  pandas.DataFrame.idxmax  __
](pandas.DataFrame.idxmax.html "next page")

__ On this page

  * ` DataFrame.first()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.first.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.
PeriodIndex.from_fields ](pandas.PeriodIndex.from_fields.html)
    * [ pandas.PeriodIndex.from_ordinals ](pandas.PeriodIndex.from_ordinals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.MultiIndex ](pandas.MultiIndex.html)
  * pandas.Multi... 

#  pandas.MultiIndex.drop  #

MultiIndex.  drop  (  _ codes  _ , _ level  =  None  _ , _ errors  =  'raise'
_ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/multi.py#L2355-L2444) #

    

Make a new [ ` pandas.MultiIndex  ` ](pandas.MultiIndex.html#pandas.MultiIndex
"pandas.MultiIndex") with the passed list of codes deleted.

Parameters  :

    

**codes** array-like

    

Must be a list of tuples when ` level  ` is not specified.

**level** int or level name, default None

    
**errors** str, default âraiseâ

    
Returns  :

    

MultiIndex

    

Examples

    
    
    >>> idx = pd.MultiIndex.from_product([(0, 1, 2), ('green', 'purple')],
    ...                                  names=["number", "color"])
    >>> idx
    MultiIndex([(0,  'green'),
                (0, 'purple'),
                (1,  'green'),
                (1, 'purple'),
                (2,  'green'),
                (2, 'purple')],
               names=['number', 'color'])
    >>> idx.drop([(1, 'green'), (2, 'purple')])
    MultiIndex([(0,  'green'),
                (0, 'purple'),
                (1, 'purple'),
                (2,  'green')],
               names=['number', 'color'])
    

We can also drop from a specific level.

    
    
    >>> idx.drop('green', level='color')
    MultiIndex([(0, 'purple'),
                (1, 'purple'),
                (2, 'purple')],
               names=['number', 'color'])
    
    
    
    >>> idx.drop([1, 2], level=0)
    MultiIndex([(0,  'green'),
                (0, 'purple')],
               names=['number', 'color'])
    

[ __ previous  pandas.MultiIndex.get_loc_level
](pandas.MultiIndex.get_loc_level.html "previous page") [ next
pandas.MultiIndex.codes  __ ](pandas.MultiIndex.codes.html "next page")

__ On this page

  * ` MultiIndex.drop()  `

[ __ Show Source
](../../_sources/reference/api/pandas.MultiIndex.drop.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.