Sep-30-2021, 03:54 PM
(Sep-30-2021, 03:35 PM)deanhystad Wrote: I think you want this:
(df['DTE'] != df['DTE'].shift(1) & df['DTE'] < 151)In pandas you use & instead of "and", | instead of "or" and ~ instead of "not"
Your code is hard to read because the lines are long. I would split the calculation from the print
value = (df['DTE'] != df['DTE'].shift(1) & df['DTE'] < 151).sum() print(f'Total number of changes in DTE value and DTE < 151 is {value}')
That gives me: TypeError: unsupported operand type(s) for &: 'float' and 'float'. Wrapping each of the individual & arguments in parentheses works:
print('Total number of changes in DTE value is {}'.format((df['DTE'] != df['DTE'].shift(1)).sum())) value = ((df['DTE'] != df['DTE'].shift(1)) & (df['DTE'] < 151)).sum() print(f'Total number of changes in DTE value and DTE < 151 is {value}')Thanks for your help!