To plot a waterfall, I create three lists as input: the value, the bar text, the axis text. My goal is to sort every number in between the first and last element ascending, i.e. exclude the first and last element in the list from being sorted.
I have three lists containing following elements:
A = [50000,8000,-3000,-4000,51000]
B = ['Start','Profit1','Cost2','Cost1','End']
C = ['50K','8k','-3k','-4k','51k']
Using the suggested method here (sort values in list by other list), I state:
a_new = sorted(A)
b_new = [x for _, x in sorted(zip(A, B))]
c_new = [x for _, x in sorted(zip(A, C))]
print(a_new)
print(b_new)
print(c_new)
And receive as Output:
[-4000, -3000, 8000, 50000, 51000]
['Cost1', 'Cost2', 'Profit1', 'Start', 'End']
['-4k', '-3k', '8k', '50K', '51k']
Though, my goal is to fix the first and the last element of the list and sort all other elements only. Desired:
[50000,-4000,-3000,8000,51000]
['Start','Cost1', 'Cost2', 'Profit1','End']
['50K','-4k', '-3k', '8k','51k']
I think I am close to the solution, but have been stuck here for quite some time...