jeudi 16 juillet 2020

List comprehension with binary outcome and time data in Python

I want to write an if loop so that it labels "1" when a certain condition is fulfilled and "0" if not. This is my code for now but I can't get it to work..

order = [1 for x in df.orderdate if x >= 2019-02-27  and x <= 2019-03-31 else 0]

(I'm also trying to use list comprehension here as well.) For the "orderdate" column I've converted everything to datetime64[ns]. Now I want to know if the customer placed an order between 2019-02-27 and 2019-03-31 or not. I want to create a new column with only 1s and 0s in it and append the column to a df I created.

Thank you so much for the help!!!!

Aucun commentaire:

Enregistrer un commentaire