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

236
Vistas
Pandas map to a new column, SettingWithCopyWarning

In pandas data frame, I'm trying to map df['old_column'], apply user defined function f for each row and create a new column.

df['new_column'] = df['old_column'].map(lambda x: f(x))

This will give out "SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame." error.

I tried the following:

df.loc[:, 'new_column'] = df['old_column'].map(lambda x: f(x))

which doesn't help. What can I do?

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

0

A SettingWithCopy warning is raised for certain operations in pandas which may not have the expected result because they may be acting on copies rather than the original datasets. Unfortunately there is no easy way for pandas itself to tell whether or not a particular call will or won't do this, so this warning tends to be raised in many, many cases where (from my perspective as a user) nothing is actually amiss.

Both of your method calls are fine. If you want to get rid of the warning entirely, you can specify:

pd.options.mode.chained_assignment = None

See this StackOverflow Q&A for more information on this.

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