import numpy as np import pandas as pd d = { 0: [1,0,1,0,0], 1: [1,0,0,1,0], 2: [0,1,0,1,0], 3: [0,1,0,0,1], 4: [0,0,1,0,1] } df = pd.DataFrame(d, index=[0,1,2,3,4]) row_idx = 0 column_idx = 1 def remove_cell(mydf=df, row_idx=0, column_idx=0): result = mydf.drop(row_idx, axis=0).drop(column_idx, axis=1) return result print df def recur(result=df, mapping=[]): if result.shape == (0,0): print mapping return first_column_index = result.columns.values[0] first_column = result[first_column_index] for row_index, value in first_column.iteritems(): if value == 1: newmapping = mapping[:] newmapping.append((row_index, first_column_index)) old_matrix = result.copy() newmatrix = remove_cell(old_matrix, row_index, first_column_index) recur(newmatrix, newmapping) recur(result=df)