mardi 18 août 2020

Error when using IF condition and s.str.startswith

Im using str.startswith and if condition to 'do something' if the condition is TRUE. I have been browsing and kind of understand that for the if condition, it is unclear what to do with it. I not sure how exactly how to obtain the solution for my problem. The code I wrote first is:

for i in Bus.index:
    if rows in (Bus['NAME'].str.startswith("S")) are True, Then:
        print(i) 

This give me error (The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()).

I am trying to say:

for i in Bus.index:
    if rows in (Bus['NAME'].str.startswith("S")) are True, Then:
        print(i)
        and if it is false then do nothing.

Aucun commentaire:

Enregistrer un commentaire