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

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

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 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!