我正在尝试创建一个列,其中包含每个id的唯一值(与每个id关联的行数众多),如果id的任何行都带有answered标签,则应该将与该id相关的所有行标记为answered。如果与id关联的所有行都没有回答标签,则所有行都应标记为未回答(这是当前的情况)。
这是我编写的代码:
import numpy as np
在这种情况下,期望的结果将是:
这是我编写的代码:
import numpy as np
conds = [file.data__answered_at.isna(),file.data__answered_at.notna()]
choices = ["not answered","answered"]
file['call_status'] = np.select(conds,choices,default=np.nan)
data__id call_status rank
1 answered 1
1 not_answered 2
1 answered 3
2 not_answered 1
2 answered 2
3 not_answered 1
4 answered 1
4 not_answered 2
5 not_answered 1
5 not_answered 2
在这种情况下,期望的结果将是:
data__id call_status rank
1 answered 1
1 answered 2
1 answered 3
2 answered 1
2 answered 2
3 not_answered 1
4 answered 1
4 answered 2
5 not_answered 1
5 not_answered 2