删除列 Dataframe 中具有相同值的行

Delete the rows that have the same value in the columns Dataframe

我有一个这样的数据框:

origin destination
germany germany
germany italy
germany spain
USA USA
USA spain
Argentina Argentina
Argentina Brazil

并且我想过滤同一个国家的路由,也就是我想获取如下dataframe:

origin destination
germany italy
germany spain
USA spain
Argentina Brazil

我如何用 pandas 做到这一点?我试过删除重复项,但没有得到我想要的结果

使用简单的过滤器:

df = df[df['origin'] != df['destination']]

输出:

>>> df
      origin destination
1    germany       italy
2    germany       spain
4        USA       spain
6  Argentina      Brazil

我们可以query:

out = df.query('origin!=destination')

输出:

      origin destination
1    germany       italy
2    germany       spain
4        USA       spain
6  Argentina      Brazil