Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!