我有一个看起来像这样的数据框:
index A ... pheno
0 0.8 0
:
500000 1.4 5
其中pheno是介于0到5之间的int
。
我想遍历行并检查pheno
列,然后根据pheno中的值创建一个新列,因此,如果pheno为0,则新列class
将为1。 / p>
如此:
index A ... pheno class
0 0.8 0 1
:
500000 1.4 5 3
我知道如何使用df.iterrows
和if/elif
来执行此操作,但想知道是否有比为每个pheno
值生成5条elif语句更快的方法?
只需添加-在某些情况下,我的pheno
列最多可包含13个以上的值,因此为什么我认为if/elif
效率低下。