jeudi 22 juillet 2021

Creating a variables (one-line if command line Python)

Im trying to create a variable with an if statement. Basically, the new column 'Region' has to take as based if the column 'State'. If State is PR then Region is PR else region is US I tried the following:

(unfunded_accounts['Region']=='US' if unfunded_accounts['State']!='PR' else unfunded_accounts['Region']=='PR')

but it says

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

Aucun commentaire:

Enregistrer un commentaire