I'm working in pandas doing pivot tables and when doing the groupby (to count distinct observations)
aggfunc={"person":{lambda x: len(x.unique())}}
gives me the following error:
'DataFrame' object has no attribute 'unique'
any ideas how to fix it?
DataFrames do not have that method; columns in DataFrames do:
df['A'].unique()
Or, to get the names with the number of observations (using the DataFrame given by closedloop):
>>> df.groupby('person').person.count()
Out[80]:
person
0 2
1 3
Name: person, dtype: int64