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

1K
Views
TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value

I am getting the error TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value when I try to replace numeric values in multiple columns by a specific string value.

df =

TYPE  VD_1   VD_2    VD_3
AAA   1234   22122   2345
AAA   1234   2345    22122

This is how I do it:

df[df.isin([22122])] = "English"

or

df[df==22122] = "English"
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you stack the df, then you can compare the entire df against the scalar value, replace and then unstack:

In [122]:
stack = df.stack()
stack[ stack == 22122] = 'English'
stack.unstack()

Out[122]:
  TYPE  VD_1     VD_2     VD_3
0  AAA  1234  English     2345
1  AAA  1234     2345  English

or replace:

In [125]:
df.replace(22122,'English', inplace=True)
df

Out[125]:
  TYPE  VD_1     VD_2     VD_3
0  AAA  1234  English     2345
1  AAA  1234     2345  English
over 4 years ago · Santiago Trujillo Report

0

I realize this is an old question, but I believe this answer will be useful for some, as it will allow for replacing values based on complex conditionals.

In [17]: df = df.where(df!=22122, other="English")

In [18]: df
Out[18]: 
  TYPE  VD_1     VD_2     VD_3
0  AAA  1234  English     2345
1  AAA  1234     2345  English

Note that values where the condition in the where clause is not met are replaced by values in other.

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!