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

141
Vistas
avoid writing df['column'] twice when doing df['column'] = df['column']

I don't even know how to phrase this but is there a way in Python to reference the text before the equals without having to actually write it again?

** EDIT - I'm using python3 in Jupyter

I seem to spend half my life writing:

df['column'] = df['column'].some_changes

Is there a way to tell Python that I'm referencing the part before the equals sign?

For example, I would write the following, where <% is just to represent the reference to the text before the = (df['column'])

df['column'] = <%.replace(np.nan)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

you are looking for in place methods. I believe you can pass inplace=True as an argument to most methods in pandas

so it would be something just like

df['column'].replace(np.nan, inplace=True)

edit

You could also do

df["computed_column"] = df["original_column"].many_operations

so you still have access to the original data down the line. And do all the needed operations at once instead of saving each step.

One of the advantages of inplace not being the default is if you are doing a batch of operations and it fails midway your data is not mangled.

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