I have a Dataframe (series) 'df' that looks like the following:
Name
A1001
A1002
B1001
C1001
A1003
B1002
B1003
C1002
D1001
D1002
I want to create a new column called Company which should read 'Alpha' if text starts with 'A', 'Bravo' if text starts with 'B' and 'Others' if text starts with anything else.
I tried:
df['Company'] = 'Alpha' if df.Name.str.startswith('A') else 'Other'
But it gave me an error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Expected Output:
Name Company
A1001 Alpha
A1002 Alpha
B1001 Bravo
C1001 Other
A1003 Alpha
B1002 Bravo
B1003 Bravo
C1002 Other
D1001 Other
D1002 Other
How can it be done?