I've seen a few posts with this error but they don't apply to this particular situation.
Say my dataframe is as follows...
import pandas as pd
df = pd.DataFrame(np.random.randint(0,20,size=(10, 2)), columns=list('AB'))
A B
0 12 12
1 15 3
2 3 12
3 4 11
4 12 9
5 0 4
6 19 12
7 5 19
8 11 16
9 13 8
I want to create a column factor
which depends on the value of column A
.
Let's say if df[A]<=10
then factor=5
else factor=8
I tried:
df['factor'] = 5 if df['A'] <= 10 else 8
But I get an error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().