Number of unique values per column by group

后端 未结 2 1134
谎友^
谎友^ 2021-01-12 10:44

Consider the following dataframe:

      A      B  E
0   bar    one  1
1   bar  three  1
2  flux    six  1
3  flux  three  2
4   foo   five  2
5   foo    one          


        
2条回答
  •  遥遥无期
    2021-01-12 11:09

    I encountered the same problem. Upgrading pandas to the latest version solved the problem for me.

    df.groupby('A').nunique()
    

    The above code did not work for me in Pandas version 0.19.2. I upgraded it to Pandas version 0.21.1 and it worked.

    You can check the version using the following code:

    print('Pandas version ' + pd.__version__)
    

提交回复
热议问题