Skip to content
Advertisement

Setting column to true/false based on comparison of two other columns in pandas?

I have the following dataframe and I want to compare column value and predicted, if they match then I want to set the value of a column “provided” to False. I’m having difficulty doing this.

Here’s my data:

JavaScript

I want a new column to just have a True/False if value and predicted match. I tried this but to no avail:

JavaScript

I get this error:

JavaScript

Advertisement

Answer

Basically, below line will check each row and boolean result will be assigned into the new column of provided as:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement