I am working in Ipython
and trying to generate all the permutations of the columns present in the dataframe
. This issue is that I have about 15 columns in my dataframe
and the code just doesn't reach end and keeps on executing. Here is my current code:
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)
I followed this SO example. I have a 16 core and 32GB memory system and have been running this code for last 1.5 hours but its still executing and doesn't look like reaching an end. Is there some fundamental issue in the code that I have? How can I make this to run faster without affecting final result? I read that itertools.permutations
is another option. How can I modify my current code to include itertools.permutations
and achieve the same result?