Python 熊猫';数据帧';对象没有属性';独特的';

Python 熊猫';数据帧';对象没有属性';独特的';,python,pandas,pivot-table,Python,Pandas,Pivot Table,我在pandas中做数据透视表,在做groupby时(计算不同的观察值) aggfunc={“person”:{lambda x:len(x.unique())}}给出了以下错误: 'DataFrame'对象没有属性'unique' 有没有办法修复它?数据帧没有这种方法;数据帧中的列执行以下操作: df['A'].unique() 或者,使用closedloop提供的数据帧获取观察次数的名称: 使用df.drop_duplicates()函数有选择地删除重复项,而不是在数据透视表过程中删除重复

我在pandas中做数据透视表,在做groupby时(计算不同的观察值)
aggfunc={“person”:{lambda x:len(x.unique())}}
给出了以下错误:
'DataFrame'对象没有属性'unique'

有没有办法修复它?

数据帧没有这种方法;数据帧中的列执行以下操作:

df['A'].unique()
或者,使用closedloop提供的数据帧获取观察次数的名称:


使用
df.drop_duplicates()
函数有选择地删除重复项,而不是在数据透视表过程中删除重复项

例如,如果使用这些
index='c0'
columns='c1'
进行旋转,那么这个简单的步骤将产生正确的计数

在本例中,第5行与第4行重复(忽略非轴
c2

import pandas as pd
data = {'c0':[0,1,0,1,1], 'c1':[0,0,1,1,1], 'person':[0,0,1,1,1], 'c_other':[1,2,3,4,5]}
df = pd.DataFrame(data)
df2 = df.drop_duplicates(subset=['c0','c1','person'])
pd.pivot_table(df2, index='c0',columns='c1',values='person', aggfunc='count')
这将正确地输出

c1  0  1
c0      
0   1  1
1   1  1

你能试试吗:
aggfunc={“person”:pd.Series.nunique}
df.description,info?fillna呢?
c1  0  1
c0      
0   1  1
1   1  1