Home > Net >  unsupported operand type(s) for &: 'DatetimeArray' and 'DatetimeArray'
unsupported operand type(s) for &: 'DatetimeArray' and 'DatetimeArray'

Time:06-21

Sanctioned Date:- DateTime column

a = df[df['Sanctioned Date'] >= '2022-01-01']
b = df[df['Sanctioned Date'] <= '2022-06-16']

want :- a & b

CodePudding user response:

Output of a, b is filtered DataFrame, so cannot chain by &.

You can chain masks with ():

out = df[(df['Sanctioned Date'] >= '2022-01-01') & (df['Sanctioned Date'] <= '2022-06-16')]

Or use Series.between:

out = df[df['Sanctioned Date'].between('2022-01-01', '2022-06-16')]

Your solution has to be changed with remove df[] first for possible chain masks:

a = df['Sanctioned Date'] >= '2022-01-01'
b = df['Sanctioned Date'] <= '2022-06-16'
out = df[a & b]
  • Related