I have a dataframe
: dt
and a list
of column names: nn_language
EDIT: added sample data
dt = pd.DataFrame({"language1": ["english", "english123", "ingles", "ingles123", "14.0", "13", "french"],
"language2": ["englesh", "english123", "ingles", "ingles123", "14", "13", "french"]})
nn_language = dt.columns[dt.columns.str.contains("language")]
All the elements of dt[nn_language]
are of object
type.
What I would like to do, is change the initial values of the dt[nn_language]
to "english"
if the initial value is like
("english","ingles",14)
else i want to change the initial value to "other"
I have tried: dt[nn_language].apply(lambda x: 'english' if x.str.contains('^engl|^ingl|14.0') else 'other')
but i get an error ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().',