【发布时间】:2018-07-11 02:52:57
【问题描述】:
我有一个这样的数据框:
id year Q
1 2017 1
2 2017 2
3 2018 1
4 2018 2
5 2018 3
并且想要创建另一个名为 D 的列:
id year Q Desc
1 2017 1 '2017 first Quarter'
2 2017 2 '2017 second Quarter'
3 2018 1 '2018 first Quarter'
4 2018 2 '2018 second Quarter'
5 2018 3 '2017 third Quarter'
然而 np.where 似乎只接受 2 个参数(如果为真,如果为假)。所以想法是有一个可以处理多种可能性的 np.where 句子
【问题讨论】:
-
np.where的多选项版本是np.select