【发布时间】:2021-05-08 13:41:26
【问题描述】:
我有一个包含两列的数据框; source 和 target。我想检测反向行,即一对值(source, target),如果存在一对值(target, source),则将True分配给一个新列。
我的尝试:
cols = ['source', 'target']
_cols = ['target', 'source']
sub_edges = edges[cols]
sub_edges['oneway'] = sub_edges.apply(lambda x: True if x[x.isin(x[_cols])] else False, axis=1)
【问题讨论】:
-
请包含您的 sub_edges DataFrame 的一小部分作为可复制 段代码,可用于测试以及您的预期或期望的输出。请参阅 MRE - Minimal, Reproducible, Example 和 How to make good reproducible pandas examples。
标签: python pandas dataframe graph networkx