Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

Sanctioned Date:- DateTime column

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

want :- a & b

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading