Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

562
Vistas
How to update pandas DataFrame.drop() for Future Warning - all arguments of DataFrame.drop except for the argument 'labels' will be keyword-only

The following code:

df = df.drop('market', 1)

generates the warning:

FutureWarning: In a future version of pandas all arguments of DataFrame.drop except for the argument 'labels' will be keyword-only

market is the column we want to drop, and we pass the 1 as a second parameter for axis (0 for index, 1 for columns, so we pass 1).

How can we change this line of code now so that it is not a problem in the future version of pandas / to resolve the warning message now?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

From the documentation, pandas.DataFrame.drop has the following parameters:

Parameters

  • labels: single label or list-like Index or column labels to drop.

  • axis: {0 or ‘index’, 1 or ‘columns’}, default 0 Whether to drop labels from the index (0 or ‘index’) or columns (1 or ‘columns’).

  • index: single label or list-like Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).

  • columns: single label or list-like Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).

  • level: int or level name, optional For MultiIndex, level from which the labels will be removed.

  • inplace: bool, default False If False, return a copy. Otherwise, do operation inplace and return None.

  • errors: {‘ignore’, ‘raise’}, default ‘raise’ If ‘ignore’, suppress error and only existing labels are dropped.

Moving forward, only labels (the first parameter) can be positional.


So, for this example, the drop code should be as follows:

df = df.drop('market', axis=1)

or (more legibly) with columns:

df = df.drop(columns='market')
over 4 years ago · Santiago Trujillo Denunciar

0

The reason for this warning is so that probably in future versions pandas will change the *args to **kwargs.

So that means specifying axis would be required, so try:

df.drop('market', axis=1)

As mentioned in the documentation:

**kwargs allows you to pass keyworded variable length of arguments to a function. You should use **kwargs if you want to handle named arguments in a function.

Also recently with the new versions (as of 0.21.0), you could just specify columns or index like this:

df.drop(columns='market')

See more here.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda