I have a list of products that are for sale on a subscription basis. the prices vary per region (about 15 regions). I'm trying to find the next closest priced product available on that day (not the cheapest on that day). My data looks like this
data = [['29/10/20', 400, 300, 2, 1],
['29/10/20', 250, 400, 1, 2],
['29/10/20', 600, 600, 3, 3],
['30/10/20', 800, 500, 3, 2]
['30/10/20', 200, 800, 1, 3],
['30/10/20', 550, 300, 2, 1]
df = pd.DataFrame(data, columns = ['date', 'east price', 'west price', 'east position', 'west position'])
I would like my ouput to look like
date east_price nearest_east_price west_price nearest_west_price
29/10/20 400 250 300 300
29/10/20 250 250 400 300
29/10/20 600 400 600 400
30/10/20 800 550 500 300
30/10/20 250 250 800 500
30/10/20 550 250 300 300
i'm not sure whether to do this bt the position information that is available or is there another way to do this. i've been stuck on this all day. i also have the problem for the cheapest product on that day, i'd like it to return its value. can anyone help? i'm new to programming so might be missing the obvious