简体   繁体   English

获得数据框的可能组合

[英]get possible combination of dataframe

100 ryan music 2 100瑞安音乐2

200 kim math 3 200 kim数学3

let say I have this dataframe 假设我有这个数据框

if I want to get a all combination of 如果我想得到

[(100,200),(ryan,kim)...(2,3)] , 
[(100ryan,200kim),(100music,200math)......], 
[(100ryanmusic),(200kimmath).....]  
[(100ryanmusic2),(200kimmath3)]

if I want to get an all relation tuple what should I do? 如果我想获取所有关系元组,该怎么办?

https://docs.python.org/2/library/itertools.html#itertools.combinations https://docs.python.org/2/library/itertools.html#itertools.combinations

example: 例:

import itertools

data = 'ABC'
for i in range(1, len(data) + 1):
    comb = itertools.combinations(data, i)
    print(list(comb))

output: 输出:

[('A',), ('B',), ('C',)]
[('A', 'B'), ('A', 'C'), ('B', 'C')]
[('A', 'B', 'C')]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 dataframe 除以不同的可能组合,并在单独的 dataframe 中获取所有组合的随机百分比数据 - Divide the dataframe by different possible combinations and get random few percent of data for all the combination in seperate dataframe 获取 dataframe 中的值组合并实现 function - Get a combination of values in dataframe and implement a function 如何获得列表整数的所有可能组合? - How to get every possible combination of list integers? Python:获取投资组合的所有可能的权重组合 - Python: get every possible combination of weights for a portfolio 获取列表中所有可能的值组合 — Python - Get all possible combination of values in a list — Python 在Python中将函数应用于数据框中所有可能的列组合-更好的方法 - Apply a function on all possible combination of columns in a dataframe in Python — Better way Python Pandas-是否可以结合使用计数器运行dataframe.query方法 - Python Pandas - Is it possible to run a dataframe.query method in combination with a counter 根据Python中数据框中的条件创建包含所有唯一可能组合的列表 - Create list with all unique possible combination based on condition in dataframe in Python Pandas - 基于多列的组合从第二个数据框中获取值 - Pandas - Get value from second dataframe based on combination of multiple columns 如何过滤和分组 pandas DataFrame 以获得两列组合的计数 - How to filter and group pandas DataFrame to get count for combination of two columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM