How to “select distinct” across multiple data frame columns in pandas?

前端 未结 6 502
渐次进展
渐次进展 2020-12-02 14:56

I\'m looking for a way to do the equivalent to the SQL

SELECT DISTINCT col1, col2 FROM dataframe_table

The pandas sql comparison doesn\'t

6条回答
  •  没有蜡笔的小新
    2020-12-02 15:40

    You can take the sets of the columns and just subtract the smaller set from the larger set:

    distinct_values = set(df['a'])-set(df['b'])
    

提交回复
热议问题