Need to sort task such that, It should come in sequence once parent of the task is listed down. It can be approached as a Directed Acyclic Graph(DAG)
In this particular example, The main issue is: "13 ifhj 5,4,9,15" should always come after 5,4,9 and 15.But 13 is coming before 15.
I am providing sample input and expected output.
I/p:
task_no t_name Parent_Task_Numbers
1 task1 0
2 task2 0
3 task3 0
4 task4 1,2
5 task5 0
6 task6 2
7 task7 4
8 task8 6,1,4
9 task9 10
10 task10 1
11 task11 2
12 task12 3
13 task13 5,4,9,15
15 task15 7,8,2,10
Expected o/p:(This can be different than this, but the main idea should be served)
task_no t_name Parent_Task_Numbers
1 task1 0
2 task2 0
3 task3 0
5 task5 0
10 task10 1
4 task4 1,2
9 task9 10
6 task6 2
11 task11 2
12 task12 3
7 task7 4
15 task15 7,8,2,10
13 task13 5,4,9,15
8 task8 6,1,4
def sort_parent_tasks1(fileName):
df1 = pd.read_csv(fileName)
print("df1.Parent_Task_Numbers.str.split(',')", type(df1.Parent_Task_Numbers.str.split(',')))
df1.Parent_Task_Numbers.str.split(',').apply(sorted, reverse = True).str.join(',').str.strip(',')
df3 = df1.sort_values(['Parent_Task_Numbers'])
df3.to_csv("/fileData/task_files/output/test_generated1.csv")
inputFile = "/fileData/task_files/input/test.csv"
sort_parent_tasks1(inputFile)
What I am getting is: which is WRONG.
tasknumber taskname Parent_Task_Numbers
1 task1 0
2 task2 0
3 task3 0
5 task5 0
10 task10 1
4 task4 1,2
9 task9 10
6 task6 2
11 task11 2
12 task12 3
7 task7 4
13 task13 5,4,9,15
8 task8 6,1,4
15 task15 7,8,2,1