Goal is to apply a conditional function on a specific subset of a pandas dataframe. I kept getting error showing "('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index C')"
Dataframe:
import numpy as np
import pandas as pd
df1 = pd.DataFrame(np.arange(0,30).reshape(6,5),'row1 row2 row3 row4 row5 row6'.split(),'A B C D E'.split())
df1
A B C D E
row1 0 1 2 3 4
row2 5 6 7 8 9
row3 10 11 12 13 14
row4 15 16 17 18 19
row5 20 21 22 23 24
row6 25 26 27 28 29
Here is the function I tried
def func (x):
if x <10:
return "fit"
else:
return x + 10
df1.iloc[[1,2],[2,3]] = df1.iloc[[1,2],[2,3]].apply(func)
But then I keep getting error