mardi 17 septembre 2019

Change column (categorical) value based on another column (float)

I try to execute this code to replace all df_dash['aoh'] <=262 to standby

if df_dash['aoh'] <= 262:
   df_dash['category'] = 'standby'

However I get this error, and I cannot seem to find a way to get the right results.

Traceback (most recent call last): File "<input>", line 1, in <module> File "/Users/jacob/anaconda3/envs/MERS/lib/python3.7/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().

I have read about this error in other threads, but I cannot seem to find a solution to this specific case.

I tried using this as well

df_dash['category'] = np.where(df_dash['aoh'] <= 262, 'standby', df['category'])

But, I get

ValueError: operands could not be broadcast together with shapes (458,) () (4173,) 

Hoping someone could help

Aucun commentaire:

Enregistrer un commentaire