[ Web Proxy ]
URL:
Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.pandas.DataFrame.drop.html [Back]  [Original]

bigframes.pandas.DataFrame.drop — bigframes documentation
Back to top
Search the docs ...:

bigframes.pandas.DataFrame.drop#

DataFrame.drop(labels: Any = None, *, axis: Union[int, str] = 0, index: Any = None, columns: blocks.Label | Sequence[blocks.Label] = None, level: Optional[LevelType] = None, inplace: Literal[False] = False) DataFrame[source]#
DataFrame.drop(labels: Any = None, *, axis: Union[int, str] = 0, index: Any = None, columns: blocks.Label | Sequence[blocks.Label] = None, level: Optional[LevelType] = None, inplace: Literal[True]) None

Drop specified labels from columns.

Remove columns by directly specifying column names.

Examples:

>>> df = bpd.DataFrame(np.arange(12).reshape(3, 4),
...                    columns=['A', 'B', 'C', 'D'])
>>> df
   A  B   C   D
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11

[3 rows x 4 columns]

Drop columns:

>>> df.drop(['B', 'C'], axis=1)
   A   D
0  0   3
1  4   7
2  8  11

[3 rows x 2 columns]
>>> df.drop(columns=['B', 'C'])
   A   D
0  0   3
1  4   7
2  8  11

[3 rows x 2 columns]

Drop a row by index:

>>> df.drop([0, 1])
   A  B   C   D
2  8  9  10  11

[1 rows x 4 columns]

Drop columns and/or rows of MultiIndex DataFrame:

>>> midx = pd.MultiIndex(levels=[['llama', 'cow', 'falcon'],
...                              ['speed', 'weight', 'length']],
...                      codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
...                             [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> df = bpd.DataFrame(index=midx, columns=['big', 'small'],
...                    data=[[45, 30], [200, 100], [1.5, 1], [30, 20],
...                          [250, 150], [1.5, 0.8], [320, 250],
...                          [1, 0.8], [0.3, 0.2]])
>>> df
                 big  small
llama  speed    45.0   30.0
       weight  200.0  100.0
       length    1.5    1.0
cow    speed    30.0   20.0
       weight  250.0  150.0
       length    1.5    0.8
falcon speed   320.0  250.0
       weight    1.0    0.8
       length    0.3    0.2

[9 rows x 2 columns]

Drop a specific index and column combination from the MultiIndex DataFrame, i.e., drop the index 'cow' and column 'small':

>>> df.drop(index='cow', columns='small')
                 big
llama  speed    45.0
       weight  200.0
       length    1.5
falcon speed   320.0
       weight    1.0
       length    0.3

[6 rows x 1 columns]
>>> df.drop(index='length', level=1)
                 big  small
llama  speed    45.0   30.0
       weight  200.0  100.0
cow    speed    30.0   20.0
       weight  250.0  150.0
falcon speed   320.0  250.0
       weight    1.0    0.8

[6 rows x 2 columns]
Parameters:
  • labels Index or column labels to drop. A tuple will be used as a single label and not treated as a list-like.

  • axis Whether to drop labels from the index (0 or index) or columns (1 or columns).

  • index Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).

  • columns Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).

  • level For MultiIndex, level from which the labels will be removed.

Returns:

DataFrame without the removed column labels.

Return type:

bigframes.pandas.DataFrame

Raises:
  • KeyError If any of the labels is not found in the selected axis.

  • ValueError If values for both labels and index/columns are provided.

  • ValueError If a multi-index tuple is provided as level.

  • ValueError If either labels or index/columns is not provided.


Web Proxy Viewer  |  New URL  |  Original Page