简体   繁体   中英

Copy values from one column to another if values equal to a certain number

Could anyone show me how to copy values in the column( m/z ) to a new column if its value equals to 300 or 305? If its value doesn't equal to 300 or 305, put 0 in the new column. It should look as follows.

在此处输入图像描述

You could do:

df['300'] = 0
df['305'] = 0

df['300'][df['m/z'] == 300] = 300
df['305'][df['m/z'] == 305] = 305

But i'm sure there might be a better way haha

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