如何从数据框B中的列(母亲年龄)中减去数据框A中的列(儿童年龄)?

2024-09-25 06:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

拜托伙计们。 如何比较数据框A和数据框B中的圆列。 在数据框A中,我有母亲的年龄,数据框B中,我有孩子的年龄。 我想得到所有与孩子相差10年的母亲数据。例如(母子年龄相差10岁) 如图中所示,母亲有一个以上的孩子。 ->;忽略编辑和英语

Screenshot


Tags: 数据gt编辑孩子screenshot年龄伙计母亲
1条回答
网友
1楼 · 发布于 2024-09-25 06:34:08

此代码将为您提供满足请求的id的名称。你知道吗

mothers_names_list = []
for id in mothers.from_uniqe_id.unique():
    mother_age = mothers[mothers.from_uniqe_id == id].BB
    tmp = childs[(childs.from_uniqe_id == id) & ((mother_age - childs.BB) > 10)]
        if tmp.shape[0] > 0: # Say if it have min of 1 child 
            mothers_names_list.append(tmp.from_uniqe_id)

相关问题 更多 >