I'm trying to generate variable which is value depend on the value of another variable. My dataset is urban_classification
and I am trying to create the variable URBRUR
based on the value of the variable prc_urbain
. This is my code:
if urban_classification.prc_urbain>0.5 :
urban_classification['URBRUR'] = "urban"
else:
urban_classification['URBRUR'] = "rural"
and I get this error message:
Traceback (most recent call last):
File "C:\Users\Utilisateur\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-a94aadb86c32>", line 31, in <module>
if urban_classification.prc_urbain>0.5 :
File "C:\Users\Utilisateur\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\generic.py", line 1555, in __nonzero__
self.__class__.__name__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can you indicate me what I am doing wrong?
Thanks!