简体   繁体   中英

How to use pandas isin() with IF statement

我在数据帧(file1)中有一个列(INT_STATUS),并且INT_STATUS的值从A到Z和1到9。如果INT_STATUS列的值在此列表中[[B','C','F','H ','P','R','T','X','Z','8','9'],然后我想创建一个新列“ rcut”并给出值“ 01” file1 [ 'rcut'] =='01'

您可以使用loc进行分配

file1.loc[file1['INT_STATUS'].isin(l), 'rcut'] = '01'

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