I'm working through a beginner's ML code, and in order to count the number of unique samples in a column, the author uses this code:
def unique_vals(rows, col):
"""Find the unique values for a column in a dataset."""
return set([row[col] for row in rows])
I am working with a DataFrame however, and for me, this code returns single letters: 'm', 'l', etc. I tried altering it to:
set(row[row[col] for row in rows)
But then it returns:
KeyError: "None of [Index(['Apple', 'Banana', 'Grape' dtype='object', length=2318)] are in the [columns]"
Thanks for your time!