简体   繁体   中英

How to join two columns and label category using DataFrame?

I have two massive columns that I want to join together and then assign values to labels

ed_adm_order_md_dept    adm_order
INTERNAL MEDICINE       NaN
INTERNAL MEDICINE       NaN
INTERNAL MEDICINE       NaN
     NaN                ADMIT FOR SURGERY
EMERGENCY MEDICINE      NaN
INTERNAL MEDICINE       NaN
INTERNAL MEDICINE       NaN
INTERNAL MEDICINE       NaN
ORTHOPEDIC SURGERY      NaN
                        ADMIT
                        ADMIT
                        ADMIT

output could be something like this

ed_adm_order_md_dept    
INTERNAL MEDICINE       
INTERNAL MEDICINE       
INTERNAL MEDICINE      
***ADMIT FOR SURGERY***                
EMERGENCY MEDICINE      
INTERNAL MEDICINE       
INTERNAL MEDICINE       
INTERNAL MEDICINE       
ORTHOPEDIC SURGERY      
    ADMIT       
ADMIT       
ADMIT

I think you want something like this:

df.ed_adm_order_md_dept.where(df.ed_adm_order_md_dept, df.adm_order)

That is, take the value of the first column where it exists, otherwise the second column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM