1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Get all keys from GroupBy object in Pandas

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking for a way to get a list of all the keys in a GroupBy object, but I can't seem to find one via the docs nor through Google.

    There is definitely a way to access the groups through their keys, like so:

    df_gb = df.groupby(['EmployeeNumber'])
    df_gb.get_group(key)


    ...so I figure there's a way to access a list (or the like) of the keys in a GroupBy object. I'm looking for something like this:

    df_gb.keys
    Out: [1234, 2356, 6894, 9492]


    I figure I could just loop through the GroupBy object and get the keys that way, but I think there's got to be a better way.

    Continue reading...

Compartilhe esta Página