Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中获得数据帧中三列的所有组合>;_Python_Pandas_Combinations_Data Science - Fatal编程技术网

如何在python中获得数据帧中三列的所有组合>;

如何在python中获得数据帧中三列的所有组合>;,python,pandas,combinations,data-science,Python,Pandas,Combinations,Data Science,三列的所有可能组合 我不能用itertools.compositions或itertools.permutation来完成 输入数据帧: a b c 1 101 1001 2 102 1002 3 103 1003 a b c 1 101 1001 1 101 1002 1 101 1003 1 102 1001 1 102 1002 1 102 1003 1 103 1001 1 103 1002 1 103 1003 2

三列的所有可能组合

我不能用itertools.compositions或itertools.permutation来完成

输入数据帧:

a   b   c
1   101 1001
2   102 1002
3   103 1003
a   b   c
1   101 1001
1   101 1002
1   101 1003
1   102 1001
1   102 1002
1   102 1003
1   103 1001
1   103 1002
1   103 1003
2   101 1001
2   101 1002
2   101 1003
2   102 1001
2   102 1002
2   102 1003
2   103 1001
2   103 1002
2   103 1003
3   101 1001
3   101 1002
3   101 1003
3   102 1001
3   102 1002
3   102 1003
3   103 1001
3   103 1002
3   103 1003
预期数据帧:

a   b   c
1   101 1001
2   102 1002
3   103 1003
a   b   c
1   101 1001
1   101 1002
1   101 1003
1   102 1001
1   102 1002
1   102 1003
1   103 1001
1   103 1002
1   103 1003
2   101 1001
2   101 1002
2   101 1003
2   102 1001
2   102 1002
2   102 1003
2   103 1001
2   103 1002
2   103 1003
3   101 1001
3   101 1002
3   101 1003
3   102 1001
3   102 1002
3   102 1003
3   103 1001
3   103 1002
3   103 1003

使用
itertools.product

from  itertools import product
#all columns
df = pd.DataFrame(list(product(*df.values.T)))
#if you need to specify columns
#df = pd.DataFrame(list(product(*[df.a, df.b, df.c])))
print (df)