Is it possible to do a unique count for the values of 2(or multiple) rows in a dataframe? I was able to do unique count with df['count'] = df.iloc[:, 0:6].nunique(axis=1) of the first 6 columns of individual. However, i can't figure out (or find) how to get the unique count of the 6 columns in both(or multiple) rows.
original df: there are 3 unique values in each row: 7,4,2 and 8,5,6
╔═════╦══════╦══════╦══════╦═════╦═════════╦════════╦═══════╗ ║ hf0 ║ hf1 ║ hf2 ║ hf3 ║ hf4 ║ hf5 ║ sample ║ count ║ ╠═════╬══════╬══════╬══════╬═════╬═════════╬════════╬═══════╣ ║ 7 ║ 4 ║ 2 ║ 2 ║ 7 ║ 2 ║ 7yr ║ 3 ║ ║ 8 ║ 5 ║ 5 ║ 6 ║ 5 ║ 6 ║ 7yr ║ 3 ║ ╚═════╩══════╩══════╩══════╩═════╩═════════╩════════╩═══════╝
df trying to get: there are 6 unique values for both rows: 7,4,2,8,5,6
╔═════╦══════╦══════╦══════╦═════╦═════════╦════════╦════════╦════════════╗ ║ hf0 ║ hf1 ║ hf2 ║ hf3 ║ hf4 ║ hf5 ║ sample ║ count ║ count2rows ║ ╠═════╬══════╬══════╬══════╬═════╬═════════╬════════╬════════╬════════════╣ ║ 7 ║ 4 ║ 2 ║ 2 ║ 7 ║ 2 ║ 7yr ║ 3 ║ 6 ║ ║ 8 ║ 5 ║ 5 ║ 6 ║ 5 ║ 6 ║ 7yr ║ 3 ║ 6 ║ ╚═════╩══════╩══════╩══════╩═════╩═════════╩════════╩════════╩════════════╝
code for sample df:
import pandas as pd
import numpy as np
data = {'hf0':[7,8],'hf1':[4,5], 'hf2':[2,5],'hf3':[2,6],'hf4':[7,5],'hf5':[2,6],'sample':['7yr','7yr']}
df = pd.DataFrame(data)
df['count'] = df.iloc[:, 0:6].nunique(axis=1)
df
Thanks in advance