Let's say I have a dataframe with a column of closing prices, and a separate (not included in the dataframe) list of max's like so:
Closes Max's
1 3
2 5
3 7
4 6
5 2
4
3
2
1
What is a pythonic way to add another column to the dataframe, where it grabs the next biggest number, comparing each close to the numbers in the list? Such that, the expected output would be:
Closes Next_Biggest
1 2
2 3
3 5
4 5
5 6
4 5
3 5
2 3
1 2
Something pseudo like:
df['Next_Biggest'] = i where df['Closes'] > i and < i for i in Max's
...or maybe to sort the Max's list from smallest to largest and then somehow loop through each Closes and compare one at a time to see if it's less than the current Max it's trying to compare to? Help! Thanks!