0

I tried to create a new column for my dataset with conditions, however, my jupyter shows the erroe:ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Here is my target:

Create a new column called ‘ind_comp’ that displays either 'Above' or 'Below'. Companies with 'pbk' equal to or higher than 'ind_pbk' should have a value‘Above’. The remainder should be ‘Below’.

And my Codes:

def cat(col1,col2):
    if col1-col2>=0:
        result="Above"
    else:
        result= "Below"
    return result

rsh_df['ind_comp']=cat(rsh_df['pbk'],rsh_df['ind_pbk'])

How can I fix this? Thanks

Saravanan
  • 7,637
  • 5
  • 41
  • 72
  • Welcome to Stack Overflow. [Please try](https://meta.stackoverflow.com/questions/261592/) to do research before asking questions, and look for existing versions of the question - for example by [using a search engine](https://duckduckgo.com/?q=site%3Astackoverflow.com+The+truth+value+of+a+Series+is+ambiguous.+Use+a.empty%2C+a.bool()%2C+a.item()%2C+a.any()+or+a.all()). – Karl Knechtel Sep 18 '22 at 11:11
  • Please also try to think carefully about the logic of the problem. How do you want the `cat` function to work? For example, when we set a `result` of `"Above"` or `"Below"`, is that creating an entire column? Or only one cell? Therefore, should the *input* be both entire columns? or just a cell from each column? – Karl Knechtel Sep 18 '22 at 11:16

0 Answers0