I have the following dataset:
I am trying to tell pandas that:
If Report No. is below 30, he needs to create a new variable that is equal to
df_bei_index[col]*0.05 + df_bei_index['PDI_Average']*0.95.
If Report No. is higher or equal to 30, he needs to create a new variable that is equal to
df_bei_index[col]
I wrote the following code:
for col in col_list:
if df_bei_index['Report No'] <= 29:
df_bei_index[col+'_final'] = df_bei_index[col]*0.05 + df_bei_index['PDI_Average']*0.95
else:
df_bei_index[col+'_final'] = df_bei_index[col]
But I get this error
ValueError Traceback (most recent call last) in () 10 11 for col in col_list: ---> 12 if df_bei_index['Report No'] <= 29: 13 df_bei_index[col+'_final'] = df_bei_index[col]*0.05 + df_bei_index['PDI_Average']*0.95 14 else:
~\Anaconda3\lib\site-packages\pandas\core\generic.py in nonzero(self) 1574 raise ValueError("The truth value of a {0} is ambiguous. " 1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." -> 1576 .format(self.class.name)) 1577 1578 bool = nonzero
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().