Python Pandas : pivot table with aggfunc = count unique distinct

后端 未结 8 1726
谎友^
谎友^ 2020-12-07 13:02
df2 = pd.DataFrame({\'X\' : [\'X1\', \'X1\', \'X1\', \'X1\'], \'Y\' : [\'Y2\',\'Y1\',\'Y1\',\'Y1\'], \'Z\' : [\'Z3\',\'Z1\',\'Z1\',\'Z2\']})

    X   Y   Z
0  X1  Y2         


        
8条回答
  •  时光说笑
    2020-12-07 13:38

    aggfunc=pd.Series.nunique will only count unique values for a series - in this case count the unique values for a column. But this doesn't quite reflect as an alternative to aggfunc='count'

    For simple counting, it better to use aggfunc=pd.Series.count

提交回复
热议问题