vendredi 15 janvier 2021

Pandas: How to create new column based on 'if-else' conditions of multiple columns?

I have a hospitalization dataset with timestamp like this:


              AA                    BB                  CC                     DD
1234    {'2015-01-05': 1}    {'2016-02-05': 1,   {'2018-02-05': 1}     {'2019-04-05': 1} 
                             '2017-03-15': 2}
1235    {'2017-02-05': 1}    {'2017-05-05': 1}         NaN             {'2019-03-05': 2} 
        '2018-06-05': 1}  

In the cell, ‘key’ is the date when someone is hospitalized and ‘value’ is the number of days.

I need to create a new column for hospitalization ('Hospitalized'). The condition -- if a date can be found on [AA or BB] followed by on [CC or DD], then ‘yes’. Otherwise it is no!

Aucun commentaire:

Enregistrer un commentaire