Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda