My table:
id attribute
1 2
1 2
2 3
2 4
5 1
5 1
6 3
6 3
6 5
Now I want only to output those id
with attribute
, if the attribute is the same for each id
.
In this sample table, the output would be
id attribute
1 2
5 1
You can get unique values in column (multiple columns) from pandas DataFrame using unique() or Series. unique() functions. unique() from Series is used to get unique values from a single column and the other one is used to get from multiple columns.
select count(distinct column_name), count(column_name) from table_name; If the # of unique values is equal to the total # of values, then all values are unique.
Navigate to the "Home" option and select duplicate values in the toolbar. Next, navigate to Conditional Formatting in Excel Option. A new window will appear on the screen with options to select "Duplicate" and "Unique" values. You can compare the two columns with matching values or unique values.
SELECT id, MIN(attribute) AS attribute
FROM test
GROUP BY id
HAVING COUNT(DISTINCT attribute) = 1 ;
or:
SELECT id, MIN(attribute) AS attribute
FROM test
GROUP BY id
HAVING MIN(attribute) = MAX(attribute) ;
I would expect the last version to be quite efficient with an index on (id, attribute)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With