0

I have df with columns 'Time' and 'Col1'. I would like to write a simple function that changes the values of 'Col1' between the time intervals from 'Time' column.

I don't know why the following code produces the following error:

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

val = 5
time1 = 200
time2 = 300
def reset_value(df, val, time1, time2):
   df.loc[df['Time'] >= time1 and df['Time']<time2, 'Col1'] = val
   return df
serdar_bay
  • 271
  • 1
  • 7

1 Answers1

0

Use & for bitwise AND and add parentheses:

df.loc[(df['Time'] >= time1) & (df['Time']<time2), 'Col1'] = val

Or use Series.ge and Series.lt:

df.loc[df['Time'].ge(time1) & df['Time'].lt(time2), 'Col1'] = val
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252