问题描述
我有一个包含两个索引列 source
和 target
的数据框。我想检测反向索引值,即对于一对值 (source,target)
,如果存在一对值 (target,source)
,则将 True 分配给名为 oneway 的新列。目标是检测单向道路。我从这篇文章中尝试过Detect presence of inverse pairs in two columns of a DataFrame
edges_gdf["oneway"] = edges_gdf.apply(
lambda x: not edges_gdf[
(edges_gdf["source"] == x["target"]) &
(edges_gdf["target"] == x["source"]) &
(edges_gdf.index != x.name)].empty,axis=1)
但是需要很多秒才能实现。我不想使用 df.iterrorws()
,因为我有超过 10 万行。
有什么方法可以回答。
数据帧头
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)