I am trying to write a simple function that will give me a count of unique values from a specific column in pandas df. I would like to use the column name as the function parameter. However,the parameter does not get recognized as string inside the function.
Here is what I am trying to convert to a function where c_type is a column name.
c_type_count = data.groupby('c_type').c_type.count()
Here is the function. I use parameter column to pass the column name:
def uniques(column):
count = data.groupby(column).column.count()
print(count)
The groupby(column) part works as indented but the second reference .column stays as .column and I get an error because there is no column by that name in the df.
I understand what is happening there but since I am new to Python I don't necessarily know who to switch the syntax.