Answers for "pairwise combinations groupby"

0

pairwise combinations groupby

from itertools import combinations
ndf = df.groupby('ID')['words'].apply(lambda x : list(combinations(x.values,2)))
                          .apply(pd.Series).stack().reset_index(level=0,name='words')
# groupby ids and get all possible  pairwise combinations of words
Posted by: Guest on March-25-2022

Python Answers by Framework

Browse Popular Code Answers by Language