1

I'm trying to create a flag variable using:

df.where(((df['MOSL_Rating'] == 'Highly Effective') & (df['MOTP_Rating'] == 'Developing')) | ((df['MOSL_Rating'] == 'Highly Effective') & (df['MOTP_Rating'] == 'Ineffective')) | ((df['MOSL_Rating'] == 'Effective') & (df['MOTP_Rating'] == 'Ineffective')) | ((df['MOSL_Rating'] == 'Ineffective') & (df['MOTP_Rating'] == 'Highly Effective')) | ((df['MOSL_Rating'] == 'Ineffective') & (df['MOTP_Rating'] == 'Effective')) | ((df['MOSL_Rating'] == 'Developing') & (df['MOTP_Rating'] == 'Highly Effective')), df['disp_rating'], 1, axis=1)

but this returns ValueError: For argument "inplace" expected type bool, received type int.

If I change my code from df['disp_rating'], 1, axis=1 to df['disp_rating'], True, axis=1 it returns TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value

I've also tried np.where but have gotten similar errors.

I'm clearly missing something here. Is there a better way to do this?

edit: I've read this post as well, as it was flagged as a possible duplicate. However, I don't understand how the answer solves my problem since that is about comparing 2 dataframes and doesn't discuss at all how to use this to create a new variable using data from only a single dataframe.

LMGagne
  • 1,636
  • 6
  • 24
  • 47
  • That is np.where.. – BENY Mar 13 '18 at 20:16
  • @Wen - I tried np.where but got similar errors. I also read through the documentation and couldn't figure out how to make it work. How would you use np.where in this situation? – LMGagne Mar 13 '18 at 20:40

0 Answers0