-1

I'm trying find max value between three columns, but I get the error (The truth value of a Series is ambiguous).

I have a dataframe like this:

TR0 TR1 TR2 TR
3.25 2.19 0.15
3.0 0 0.14

I need put in column "TR" the max value between columns TR0, TR1, TR2. I'm trying this:

df.loc[:,'TR'] = max(df.loc[:,'TR0'], df.loc[:,'TR1'], df.loc[:,'TR2'])

but get the message The truth value of a Series is ambiguous

Bill
  • 10,323
  • 10
  • 62
  • 85
Alex5672
  • 13
  • 2

1 Answers1

0

The problem is your using the Python max function with Pandas series as arguments. It was not designed for that.

Use the Pandas data frame max method instead:

df['TR'] = df[['TR0', 'TR1', 'TR2']].max(axis=1)
Bill
  • 10,323
  • 10
  • 62
  • 85