Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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]}
Comment

convert pandas group to dict

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

dataframe groupby to dictionary

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]}
Comment

dict from group pandas

dict(tuple(df.groupby('a')))
Comment

PREVIOUS NEXT
Code Example
Python :: write image out opencv 
Python :: python generate string 
Python :: cursor.fetchall() to list 
Python :: flatmap in python 
Python :: append multiple values to 2d list python 
Python :: python json write utf 8 
Python :: .replit file python 
Python :: sortedcontainers sorteddict import 
Python :: raw input example py 
Python :: nested loop 
Python :: permutation python 
Python :: batch gradient descent python 
Python :: Python Datetime Get year, month, hour, minute, and timestamp 
Python :: matplotlib legend get handles 
Python :: new column with addition of other columns 
Python :: know the type of variable in python 
Python :: how to create pyw file 
Python :: strip whitespace python 
Python :: for loop example python 3 
Python :: Get a list of categories of categorical variable (Python Pandas) 
Python :: one line if statement python without else 
Python :: If elif else 
Python :: python temporary file 
Python :: word2vec 
Python :: how to print out even index in python 
Python :: return mean of df as dataframe 
Python :: python try except: print error 
Python :: split paragraphs in python 
Python :: python string replace variable 
Python :: argparse print help if no arguments 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =