我的数据框中有2列。 “成人”代表酒店房间中的成年人数,“儿童”代表房间中的儿童数。
I want to create a new column based on these two.
For example if df['adults'] == 2 and df[‘children’]==0
the value of the new column would be "couple with no children".
And if the df['adults'] = 2 and df[‘children’]=1
the value of the new column would be "couple with 1 child".
问题是我有大量数据,并且我希望代码能够快速运行。
有什么建议吗?这是我需要的输入和输出的样本。
adult children family_status
2 0 "Couple without children"
2 0 "Couple without children"
2 1 "Couple with one child"
Use
np.select