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

2
  • Welcome to Stack Overflow. Please try to do research before asking questions, and look for existing versions of the question - for example by using a search engine. Commented Sep 18, 2022 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? Commented Sep 18, 2022 at 11:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.