ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). Error in my contains function

Issue

This Content is from Stack Overflow. Question asked by Bolito

I have a problem with my script. I don’t know if i’m using the “contains” function correctly

I want to compare if the first row (zip or cg) contains any character from my second row fax

df = pd.merge(new_client.astype(str), new_groupe.astype(str), how= 'left', on='num_client')
fax = df['fax'].astype(str)
zip = df['code_zip'].astype(str)
cg = df['code_groupe'].astype(str)

    if zip.str.contains(str(fax)):
        if cg.str.contains(str(fax)):

            verif_code_groupe = "ok"
            df['verif_code_groupe'] = verif_code_groupe
    else : 
        verif_code_groupe = "nok"
        df['verif_code_groupe'] = verif_code_groupe

The script return me this error

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Thanks you for helping !



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?