dataframe groupby to dictionary

In [81]: df.groupby('Column1')['Column3'].apply(list).to_dict()
Out[81]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}

5
1
Luxembourg 80 points

                                    res = dict(tuple(d.groupby('a')))

5 (1 Votes)
0
3.7
10
Tborychowski 135 points

                                    In [433]: {k: list(v) for k, v in df.groupby('Column1')['Column3']}
Out[433]: {0: [1], 1: [2, 3, 5], 2: [1, 2], 3: [4, 5], 4: [1], 5: [1, 2, 3]}

3.7 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
dataframe groupby function map example dataframe groupby function map groupby python dict group by pandas by key groupby dictionary in python python groupby to dict pandas to dict groupby group by columns in pandas & dictionary groupby and then each group in a dict python groupby pandas into dictionary group column in pandas into dictionary pandas groupby key convert groupby to dictionary python dataframe groupby to dictionary pandas group by into dict how to group a dataframe into dict group by dataframe dictionary python pandas dataframe groupby dict of dict pandas group by columns to dict dict of groupby values pandas pandas groupby and map group by column dicts pandas pandas dataframe groupby dictionary create dict from pandas groupby python dictionary groupby pandas groupby object to dictionary group dataframe row in dict dataframe group by dictionary pandas groupby dict pandas groupby to dict pandas dataframe group by to dict dataframe groupby to_dict pandas dataframe group by dictionary pandas group by key create dictionary from groupby pandas python pandas convert nunique output to dictionart pandas dataframe to dict two columns pandas group by and convert to dictionary pandas groupby dictionary pandas groupbygroup keys pandas groupby to dictionary of dataframes groupby pandas to dict convert three column to a dictionary pandas python dataframe groupby to dictionary python dictionary to dataframe mean by group pandas aggregate groupby to dictionary of list two columns to dictionary pandas as list get dict gropby pandas convert pandas groupby to dictionary DataFrameGroupBy objects to dict python create a dictionary from two pandas columns python create a dictionary from two columns pandas python to_dict() some field pandas to_dict group by dataframe to dictionary of lists of columns with groupby df to dict group by index dataframe to dictionary with one column as key pandas row to dict pandas dataframe to dictionary pandas to dict create a dictionary from pandas dataframe pandas groupby to dict of dataframes convert pandas group to dict
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source