2
df['svc_port'] = np.where(
     min(df['sPort'],df['dPort']) <= 1024, 
     min(df['sPort'],df['dPort']), 
     df['dPort']
)

In the above code, min(df['sPort'],df['dPort']) <= 1024 - the same thing is given in Compare two columns using pandas. I am not using any logical operators. just checking a condition and replacing it's values.

Why am I still getting this error?

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Machavity
  • 29,816
  • 26
  • 86
  • 96
Kathiravan Natarajan
  • 2,778
  • 6
  • 21
  • 41

1 Answers1

2

You are looking for an element-wise min. The builtin min function only works for a single iterable, not multiple of them at a time.

What you're looking for is something along these lines, using np.minimum.

v = np.minimum(df['sPort'], df['dPort'])
df['svc_port'] = np.where(v <= 1024, v, df['dPort'])
cs95
  • 330,695
  • 80
  • 606
  • 657