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.