我试着找到一个解决方案,但我做不到:
我有一个DF,其中一列是“子”列,另一列是“父列”。
我需要检查父级是否存在于“子”列中作为子级本身,如果不存在,我想创建一个新行,其中“父级”字段中的值将作为“子级”值输入,所有其他值将手动输入。
父代-子代;a_b -父代
a_b -子;a-父
如果a_b存在,则什么也不做并检查下一行,如果不存在-使用"a“父级创建"a_b”子级
非常感谢:)
发布于 2020-06-24 22:15:02
我将您的示例视为示例数据帧
child parent
0 a_b_c a_b
1 a_b a下面的代码提取父级不在子列中的行
child_exists = df.parent.apply(lambda x: x in df.child.tolist())
df[~child_exists].parent # This will return the parents not present in the child colhttps://stackoverflow.com/questions/62554474
复制相似问题