I want to get the minimum price first in a list... this is my code
for link in productlinks:
try:
r = requests.get(link, headers=headers)
soup = BeautifulSoup(r.content, 'lxml')
name = soup.find(
'h1', class_='product-main__name').text.strip()
price = soup.find(
'p', class_='product-action__price').text.strip()
price = price.replace('£', '')
Aitems = {
'price': price,
'name': name
}
itemlist.append(Aitems)
print('Saving:', Aitems['price'])
except AttributeError:
continue
df = pd.DataFrame(itemlist)
print(min(df['price']))
Output:
Saving: 30.45
Saving: 31.95
Saving: 32.75
Saving: 32.95
Saving: 29.45
Saving: 38.95
Saving: 40.95
29.45
I can get the minimum value of that code but I want the whole list of the "products" so it starts with the minimum value up to the maximum value.
Output
name price
0 Suntory Torys Classic 30.45 < "I want it to start with the minimum value"
1 Suntory Toki 31.95
2 Akashi Blended Whisky 32.75
3 Tokinoka White Blended Whisky 32.95
4 Hatozaki Blended Japanese Whisky 29.45
5 Nikka Days 38.95
Is there a simple way I can do it?
I tried
print(df.sort_values(by=['price']))
But it did not sort the minimum price. It was kind of random numbers. Here is the output:
38 Ichiro's Malt Wine Wood Reserve 115
37 Ichiro's Malt MWR\nMizunara Wood Reserve 115
52 Suntory Yamazaki Puncheon\nBot.2013 1200
51 Suntory Yamazaki Bourbon Barrel\nBot.2013 1200
39 Suntory Yamazaki 12 Year Old 125
40 Okayama Single Malt 147