Suppose I have four columns A, B, C, D in a data frame df:
import pandas as pd
df = pd.read_csv('results.csv')
df
A B C D
good good good good
good bad good good
good bad bad good
bad good good good
I want to add an other column result. The variables in it should be based on the corresponding rows' variables. Here, in my case, if there are at least three goods in the corresponding row i.e. in the columns A, B, C, D then the variable in results should be valid otherwise notvalid.
Expected output:
A B C D results
good good good good valid
good bad good good valid
good bad bad good notvalid
bad good good good valid