0

I am trying to do comparison on two values in each row. If the first value is smaller than the second one, don't change it. Otherwise, change it to the second one. Here is my code.

dataFrame = pd.DataFrame({"value":[1,10,8,9,7],"max":[5,8,7,10,6]})

dataFrame['value'].apply(lambda x: dataFrame['max'] if x > dataFrame["max"] else x)

my dataFrame is like this

And here is my error. "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."

I kinda understand what this error is about, it's saying that two Series of values when they do comparison, the trues/falses are also a series. But how could I do comparison on two column values in each row and then fill a value in one column of that row.

HerneS
  • 1
  • If still problem what is expected ouput? do you need `dataFrame['value'].mask(dataFrame['value']>dataFrame["max"], dataFrame["max"])` ? – jezrael May 26 '22 at 08:45
  • Yes, appreciate it! Many thanks even thought the question is closed. – HerneS May 27 '22 at 23:17

0 Answers0