Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.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
在Ipython中生成数据帧中所有列排列时出现的问题_Python_Algorithm_Dataframe_Permutation_Combinatorics - Fatal编程技术网

在Ipython中生成数据帧中所有列排列时出现的问题

在Ipython中生成数据帧中所有列排列时出现的问题,python,algorithm,dataframe,permutation,combinatorics,Python,Algorithm,Dataframe,Permutation,Combinatorics,我正在Ipython中工作,试图生成dataframe中存在的所有列的排列。这个问题是,我的dataframe中大约有15列,而代码只是没有到达末尾并继续执行。这是我目前的代码: df = pd.read_csv(filename, sep = ';', error_bad_lines=False) def all_perms(str): if len(str) <=1: yield str else: for perm in all_pe

我正在
Ipython
中工作,试图生成
dataframe
中存在的所有列的排列。这个问题是,我的
dataframe
中大约有15列,而代码只是没有到达末尾并继续执行。这是我目前的代码:

df = pd.read_csv(filename, sep = ';', error_bad_lines=False)

def all_perms(str):
    if len(str) <=1:
        yield str
    else:
        for perm in all_perms(str[1:]):
            for i in range(len(str)):
                #nb str[0:1] works in both string and list contexts
                yield perm[:i] + str[0:1] + perm[i:]

allperms_list = []
for p in all_perms(df.columns[:len(df.columns)]):
    allperms_list.append(p) 
df=pd.read\u csv(文件名,sep=';',错误\u bad\u line=False)
定义所有项目(str):

if len(str)
来自itertools导入置换;对于排列中的p(df.columns)):打印p
,您有多少列?@padraiccanningham我的数据框架中有15列不应在1.5秒内运行hours@PadraicCunningham是的,这就是为什么我认为我在我的生活中犯了一些错误code@PadraicCunningham在我上面的代码中有什么错误吗?在速度方面,使用
itertools.permutations
比上述方法更好(在复杂性方面,在itertools.permutations中使用两行代码显然比我的方法更好)?