Hope anyone with good experience on BS4 can help me. I have a very headache.
I want to get: Product title, price, picture and url from
https://www.offspring.co.uk/view/category/offspring_catalog/NEWIN?pageSize=100&sort=-releasedate products.
I have already got price and href (url) with the following code:
price = url.find("div", "price js-price") (PRICE)
Purl = url.find("a").attrs['href'] (URL)
However picture is giving me problem doing:
picture = url.find("img").attrs["src"] and what is more important I don't know how can I get product tittle because it's like in a weird class.
For example on the last item called Jordan Zoom 92 Trainer, I would like to get this name , but not sure what I need to do :)
Here is picture if you don´t want to access link.
picture
Thanks a lot <3
To extract the information about each product, you can use this example:
import json
import requests
from bs4 import BeautifulSoup
url = 'https://www.offspring.co.uk/view/category/offspring_catalog/NEWIN?pageSize=100&sort=-releasedate'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
for i in soup.select('.productList_item'):
link = 'https://www.offspring.co.uk' + i.a['href']
brand = i.strong.text
name = i.br.find_next_sibling(text=True).strip()
price = i.select_one('.price, .now_price')['data-value']
picture_url = json.loads(i.img['data-media'])['350']
print('{:<20} {:<35} {:<10} {:<70} {}'.format(brand, name, price, picture_url, link))
Prints:
Jordan Jordan Zoom '92 Trainers 130.0 https://i1.adis.ws/i/office/4022015374_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4022015374
Comme Des Garcons Cdg Cross Trainers 535.0 https://i1.adis.ws/i/office/4133010000_sd1.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133010000
Comme Des Garcons Cdg Cross Trainers 535.0 https://i1.adis.ws/i/office/4133000000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133000000
adidas Paris Trainers 74.99 https://i1.adis.ws/i/office/4022535270_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022535270
Nike Vapormax 2020 Trainers 190.0 https://i1.adis.ws/i/office/4016724556_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4016724556
Nike Vapormax 2020 Trainers 190.0 https://i1.adis.ws/i/office/4016724555_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4016724555
adidas Statement Hoddlesden Spzl Trainers 50.0 https://i1.adis.ws/i/office/3555150000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3555150000
Puma Bluebird Trainers 74.99 https://i1.adis.ws/i/office/4033135280_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4033135280
On-Running Cloud X Trainers 130.0 https://i1.adis.ws/i/office/4131410508_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4131410508
On-Running Cloud Trainers 120.0 https://i1.adis.ws/i/office/4129108801_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4129108801
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128915798_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128915798
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908800_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908800
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908799_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908799
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908798_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908798
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908789_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908789
On-Running Cloudswift Trainers 135.0 https://i1.adis.ws/i/office/4128908788_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4128908788
Filling Pieces Low Plain Court Trainers 175.0 https://i1.adis.ws/i/office/4122114879_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4122114879
Filling Pieces Mondo 2.0 Ripple Trainers 170.0 https://i1.adis.ws/i/office/3556324666_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3556324666
Filling Pieces Mondo 2.0 Ripple Trainers 170.0 https://i1.adis.ws/i/office/3556304550_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3556304550
Filling Pieces Low Mondo Ripple Trainers 170.0 https://i1.adis.ws/i/office/2991230475_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2991230475
Converse All Star Hi 70s Trainers 79.99 https://i1.adis.ws/i/office/1662415290_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1662415290
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143115498_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2143115498
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084815638_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084815638
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084808675_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084808675
adidas Y3 Y-3 Shiku Run Trainers 300.0 https://i1.adis.ws/i/office/4084808673_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4084808673
adidas Delpala Trainers 54.99 https://i1.adis.ws/i/office/4037704470_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4037704470
adidas Superstar Bold Trainers 89.99 https://i1.adis.ws/i/office/2669108370_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2669108370
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143115262_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2143115262
adidas Stan Smith Trainers 74.99 https://i1.adis.ws/i/office/2143114446_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2143114446
Converse All Star Ox 70s Trainers 74.99 https://i1.adis.ws/i/office/1662315290_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1662315290
adidas Superstar Trainers 79.99 https://i1.adis.ws/i/office/3844515498_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3844515498
Nike Air Max 95 150.0 https://i1.adis.ws/i/office/2026496414_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2026496414
Nike Nike Elemental Backpack 2.0 24.99 https://i1.adis.ws/i/office/3891380954_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/3891380954
adidas Zx 8000 Trainers 89.99 https://i1.adis.ws/i/office/2125815184_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2125815184
adidas Zx 500 Trainers 74.99 https://i1.adis.ws/i/office/2120067342_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2120067342
adidas Boston Super Trainers 74.99 https://i1.adis.ws/i/office/1672963106_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1672963106
adidas Zx 500 Trainers 74.99 https://i1.adis.ws/i/office/1511624536_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1511624536
Puma Bluebird Trainers 74.99 https://i1.adis.ws/i/office/4033163114_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4033163114
Nike Space Hippie 4 125.0 https://i1.adis.ws/i/office/4015340811_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4015340811
Nike Space Hippie 1 115.0 https://i1.adis.ws/i/office/3944508765_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3944508765
adidas Padiham Spezials 74.99 https://i1.adis.ws/i/office/3133467370_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3133467370
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133165000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133165000
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133160000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133160000
Comme Des Garcons Spalwart Runners 275.0 https://i1.adis.ws/i/office/4133140000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4133140000
adidas As 520 Trainers 74.99 https://i1.adis.ws/i/office/4022663107_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022663107
adidas As 520 Trainers 74.99 https://i1.adis.ws/i/office/4022652524_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4022652524
Jordan Jordan Delta Trainers 130.0 https://i1.adis.ws/i/office/3936715372_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3936715372
Nike Air Max Plus 3 Trainers 150.0 https://i1.adis.ws/i/office/3777708415_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3777708415
Nike Daybreak Trainers 89.99 https://i1.adis.ws/i/office/3557108431_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3557108431
adidas Stadt Trainers 84.99 https://i1.adis.ws/i/office/3538480932_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3538480932
adidas Stella McCartney Ultraboost 20s Trainers 200.0 https://i1.adis.ws/i/office/4066340820_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4066340820
Veja Campo Trainers 115.0 https://i1.adis.ws/i/office/3427115427_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/3427115427
adidas Stella McCartney Treino Trainers 160.0 https://i1.adis.ws/i/office/2901715555_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2901715555
Vans Sk8-Hi Slim Trainers 64.99 https://i1.adis.ws/i/office/1050408494_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/1050408494
adidas Stella McCartney Boston S Trainers 180.0 https://i1.adis.ws/i/office/4065815410_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4065815410
adidas Stella McCartney Boston S Trainers 180.0 https://i1.adis.ws/i/office/4065808567_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/4065808567
Vans Sk8 Hi Mte 2.0 Dx Trainers 100.0 https://i1.adis.ws/i/office/4027396439_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4027396439
Vans Old Skool Trainers 74.99 https://i1.adis.ws/i/office/2421896435_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2421896435
Nike Air Max III Trainers 130.0 https://i1.adis.ws/i/office/4016615343_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4016615343
adidas Zx8000 Trainers 110.0 https://i1.adis.ws/i/office/2164415678_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2164415678
Jordan Air Jordan Og Trainers 125.0 https://i1.adis.ws/i/office/3873703617_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3873703617
Jordan Jordan Zoom '92 Trainers 130.0 https://i1.adis.ws/i/office/4022008450_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4022008450
Nike Nike Flow 2020 Ispa Trainers 155.0 https://i1.adis.ws/i/office/4063667382_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4063667382
Nike Nike Flow 2020 Ispa Trainers 155.0 https://i1.adis.ws/i/office/4063666824_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4063666824
Puma Puma Oslo Trainers 79.99 https://i1.adis.ws/i/office/1352112146_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1352112146
Puma Puma Oslo Trainers 79.99 https://i1.adis.ws/i/office/1352111797_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/1352111797
adidas Sl 72 Trainers 69.99 https://i1.adis.ws/i/office/3843115257_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3843115257
Nike Air Force 1 07 Trainers 110.0 https://i1.adis.ws/i/office/2704615626_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/2704615626
Vans Vans Classic Slip Ons 54.99 https://i1.adis.ws/i/office/2496515408_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2496515408
Jordan Air Jordan 6 Trainers 170.0 https://i1.adis.ws/i/office/1642387429_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1642387429
Nike Air Max 90 Flyease Trainers 115.0 https://i1.adis.ws/i/office/4020803617_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4020803617
Nike 70's Type Trainers 79.99 https://i1.adis.ws/i/office/4015815319_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4015815319
adidas Y3 Y-3 Sprint Trainers 250.0 https://i1.adis.ws/i/office/4003101110_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4003101110
Jordan Jordan Delta Trainers 115.0 https://i1.adis.ws/i/office/3936724545_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3936724545
adidas Y3 Y-3 Yohji Star Trainers 229.0 https://i1.adis.ws/i/office/3887100000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3887100000
adidas Y3 Y-3 Yohji Pro Trainers 229.0 https://i1.adis.ws/i/office/3886900000_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3886900000
Nike Air Force 1 07 Trainers 84.99 https://i1.adis.ws/i/office/2583208441_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2583208441
Nike Blazer Mid 77 Trainers 89.99 https://i1.adis.ws/i/office/1174377157_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/1174377157
Converse Run Star Hike Trainers 89.99 https://i1.adis.ws/i/office/3543677146_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3543677146
Converse Run Star Hike Trainers 89.99 https://i1.adis.ws/i/office/3543640809_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/2,20/3543640809
Jordan Air Jordan 3 170.0 https://i1.adis.ws/i/office/1641815508_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/1641815508
adidas Zx 1000 Trainers 74.99 https://i1.adis.ws/i/office/4095915679_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/4095915679
Vans Backpack 46.99 https://i1.adis.ws/i/office/4028396449_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028396449
Vans Crew Socks 12.99 https://i1.adis.ws/i/office/4028296448_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028296448
Vans Ss T-shirt 46.99 https://i1.adis.ws/i/office/4028196446_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028196446
Vans Shallow Unstructed Cap 27.99 https://i1.adis.ws/i/office/4028096445_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/3,87/4028096445
Vans Sk8 Low Trainers 64.99 https://i1.adis.ws/i/office/4027296438_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/4027296438
Vans Comfycush Slip On Trainers 69.99 https://i1.adis.ws/i/office/3823196432_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/3823196432
Vans Sk8 Hi Zip Toddler Trainers 39.99 https://i1.adis.ws/i/office/2838496436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2838496436
Vans Authentic Kids Trainers 36.99 https://i1.adis.ws/i/office/2615596440_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2615596440
Vans Classic Slip On Kids Trainers 36.99 https://i1.adis.ws/i/office/2608196443_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2608196443
Vans Classic Slip On Toddlers 32.99 https://i1.adis.ws/i/office/2607396442_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2607396442
Vans Classic Slip On Toddlers Trainers 32.99 https://i1.adis.ws/i/office/2607396441_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/2607396441
Vans Old Skool Trainers 69.99 https://i1.adis.ws/i/office/2421896434_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421896434
Vans Sk8 Hi Trainers 74.99 https://i1.adis.ws/i/office/2421696437_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421696437
Vans Sk8 Hi Trainers 74.99 https://i1.adis.ws/i/office/2421696436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2421696436
Vans Era Trainers 59.99 https://i1.adis.ws/i/office/2209196433_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,21/2209196433
Vans Sk8 Hi Kids Trainers 49.99 https://i1.adis.ws/i/office/1834196436_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/4,85/1834196436
Converse Jack Purcell Trainers 84.99 https://i1.adis.ws/i/office/2413215636_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2413215636
Converse Jack Purcell Trainers 84.99 https://i1.adis.ws/i/office/2413208670_ls.jpg?$picture$&version=6.0.4 https://www.offspring.co.uk/view/product/offspring_catalog/5,22/2413208670
Related
I have two dataframes, I want the main one (vehicle_data_all) to have a new column with the vehicle type. I have this in another dataframe
vehicle_data_all
vehicle type
both dataframes have the column "Manufacturer"
I would like to do it with a join
Manufacturer model year price transmission mileage fuelType tax
VW Eos 2020.0 5990 Manual 74000 Diesel 125.0
VW Fox 2020.0 1799 Manual 88102 Petrol 145.0
VW Fox 2020.0 1590 Manual 70000 Petrol 200.0
VW Fox 2020.0 1250 Manual 82704 Petrol 150.0
VW Fox 2017.0 2295 Manual 74000 Petrol 145.0
I am attempting to loop over many pages of data, with the same format, to acquire one large master data frame of all the data appended together. When I run this code however, the master_df comes up empty, as if the new_df isn't being appended to the master. Any thoughts? Thanks in advance!
alphabet_list = ['a','b','c','d','e','f']
master_df = pd.DataFrame([])
for letter in alphabet_list:
player_df = pd.read_html('https://www.nfl.com/players/active/{}'.format(letter))
new_df = player_df[0]
master_df = new_df.append(new_df)
Try this change:
import pandas as pd
alphabet_list = ['a','b','c','d','e','f']
master_df = pd.DataFrame()
for letter in alphabet_list:
player_df = pd.read_html('https://www.nfl.com/players/active/{}'.format(letter))
master_df = master_df.append(player_df)
Output:
Player Current Team Position Status
0 Chidobe Awuzie Dallas Cowboys CB ACT
1 Josh Avery Seattle Seahawks DT ACT
2 Genard Avery Philadelphia Eagles OLB ACT
3 Anthony Averett Baltimore Ravens CB ACT
4 Lee Autry Chicago Bears DT ACT
5 Denico Autry Indianapolis Colts DT ACT
6 Tavon Austin Dallas Cowboys WR UFA
7 Blessuan Austin New York Jets DB ACT
8 Antony Auclair Tampa Bay Buccaneers TE ACT
9 Jeremiah Attaochu Denver Broncos LB ACT
10 Hunter Atkinson Atlanta Falcons OT ACT
11 John Atkins Detroit Lions DE ACT
12 Geno Atkins Cincinnati Bengals DT ACT
13 Marcell Ateman Las Vegas Raiders WR ACT
14 George Aston New York Giants RB ACT
15 Dravon Askew-Henry New York Giants DB ACT
16 Devin Asiasi New England Patriots TE ACT
17 George Asafo-Adjei New York Giants OT ACT
18 Ade Aruna Las Vegas Raiders DE ACT
19 Grayland Arnold Philadelphia Eagles SAF ACT
20 Dan Arnold Arizona Cardinals TE ACT
21 Damon Arnette Las Vegas Raiders CB UDF
22 Ray-Ray Armstrong Dallas Cowboys LB UFA
23 Ka'John Armstrong Denver Broncos OT ACT
24 Dorance Armstrong Dallas Cowboys DE ACT
25 Cornell Armstrong Houston Texans DB ACT
26 Terron Armstead New Orleans Saints OT ACT
27 Ryquell Armstead Jacksonville Jaguars RB ACT
28 Arik Armstead San Francisco 49ers DE ACT
29 Alex Armah Carolina Panthers FB ACT
.. ... ... ... ...
70 Mark Fields Minnesota Vikings CB ACT
71 Sam Ficken New York Jets K ACT
72 Jason Ferris Carolina Panthers LB ACT
73 Clelin Ferrell Las Vegas Raiders DE ACT
74 Reid Ferguson Buffalo Bills LS ACT
75 Josh Ferguson Washington Redskins RB ACT
76 Jaylon Ferguson Baltimore Ravens LB ACT
77 Blake Ferguson Miami Dolphins LS ACT
78 James Ferentz New England Patriots C UFA
79 Rashad Fenton Kansas City Chiefs DB ACT
80 Darren Fells Houston Texans TE UFA
81 Jon Feliciano Buffalo Bills OG ACT
82 Clayton Fejedelem Miami Dolphins DB ACT
83 Matt Feiler Pittsburgh Steelers OT RFA
84 Jordan Fehr Minnesota Vikings LB ACT
85 Breiden Fehoko Los Angeles Chargers DT ACT
86 Dan Feeney Los Angeles Chargers OG ACT
87 Tavien Feaster Jacksonville Jaguars RB ACT
88 Foley Fatukasi New York Jets DT ACT
89 Rojesterman Farris Atlanta Falcons DB ACT
90 Wesley Farnsworth Denver Broncos LS ACT
91 Matthias Farley New York Jets DB ACT
92 Noah Fant Denver Broncos TE ACT
93 George Fant New York Jets OT ACT
94 David Fales New York Jets QB ACT
95 Nico Falah Denver Broncos C ACT
96 Ka'imi Fairbairn Houston Texans K ACT
97 Jovahn Fair Kansas City Chiefs OG ACT
98 Brandon Facyson Los Angeles Chargers DB ACT
99 Kyler Fackrell New York Giants LB ACT
[571 rows x 4 columns]
I pretty new to this,
What I am trying to accomplished is having a table with distrcits and their various neighborhoods but my final code just list all neighborhoods in a list format without assigning them to a specific district.
url = "https://en.wikipedia.org/wiki/List_of_neighbourhoods_in_Toronto"
html = urlopen(url)
soup = BeautifulSoup(html, 'lxml')
type(soup)
print(soup.prettify())
Toronto_table = soup.find('table',{'class':'wikitable sortable'})
links = Toronto_table.find_all('a')
neighborhoods = []
for link in links:
neighborhoods.append(link.get('title'))
print(neighborhoods)
df_neighborhoods = pd.DataFrame(neighborhoods)
df_neighborhoods
You can simply read_html and print the table.
import pandas as pd
f_states=pd.read_html('https://en.wikipedia.org/wiki/List_of_neighbourhoods_in_Toronto')
print(f_states[6])
Output :
District Number Neighbourhoods Included
0 C01 Downtown, Harbourfront, Little Italy, Little P...
1 C02 The Annex, Yorkville, South Hill, Summerhill, ...
2 C03 Forest Hill South, Oakwood–Vaughan, Humewood–C...
3 C04 Bedford Park, Lawrence Manor, North Toronto, F...
4 C06 North York, Clanton Park, Bathurst Manor
5 C07 Willowdale, Newtonbrook West, Westminster–Bran...
6 C08 Cabbagetown, St. Lawrence Market, Toronto wate...
7 C09 Moore Park, Rosedale
8 C10 Davisville Village, Midtown Toronto, Lawrence ...
9 C11 Leaside, Thorncliffe Park, Flemingdon Park
10 C13 Don Mills, Parkwoods–Donalda, Victoria Village
11 C14 Newtonbrook East, Willowdale East
12 C15 Hillcrest Village, Bayview Woods – Steeles, Ba...
13 E01 Riverdale, Danforth (Greektown), Leslieville
14 E02 The Beaches, Woodbine Corridor
15 E03 Danforth (Greektown), East York, Playter Estat...
16 E04 The Golden Mile, Dorset Park, Wexford, Maryval...
17 E05 Steeles, L'Amoreaux, Tam O'Shanter – Sullivan
18 E06 Birch Cliff, Oakridge, Hunt Club, Cliffside
19 E08 Scarborough Village, Cliffcrest, Guildwood, Eg...
20 E09 Scarborough City Centre, Woburn, Morningside, ...
21 E10 Rouge (South), Port Union (Centennial Scarboro...
22 E11 Rouge (West), Malvern
23 W01 High Park, South Parkdale, Swansea, Roncesvall...
24 W02 Bloor West Village, Baby Point, The Junction (...
25 W03 Keelesdale, Eglinton West, Rockcliffe–Smythe, ...
26 W04 York, Glen Park, Amesbury (Brookhaven), Pelmo ...
27 W05 Downsview, Humber Summit, Humbermede (Emery), ...
28 W06 New Toronto, Long Branch, Mimico, Alderwood
29 W07 Sunnylea (The Queensway – Humber Bay)
30 W08 The Kingsway, Central Etobicoke, Eringate – Ce...
31 W09 Kingsview Village-The Westway, Richview (Willo...
32 W10 Rexdale, Clairville, Thistletown - Beaumond He...
Trying to figure out an issue that is causing my SQL Server query to return no results. I have a query which calls out where there is more than one unique 'requested delivery date' at a size level on a single PO. I do this using COUNTand DISTINCT. It works perfect until I add the fields 'PO_ITEM_NUMBER' and 'REQ_DELIV_DATE'- this was requested by the business. I am not sure why that would cause an issue - for reference our tier for PO tables is Header,Item,Size - size being the most granular and it is SAP based.
Query:
SELECT E.TEAM_MEMBER_NAME [EMPLOYEE],
H.PO_TYPE,
H.PO_ISSUE_DATE,
S.PO_NUMBER,
S.MATERIAL,
M.DESCRIPTION,
H.PO_ORDERED_QUANTITY [PO_QUANTITY], -- if you sue SUM(S.PO_ORDERED_QUANTITY - you get more results but wrong totals
K.BUSINESS_SEGMENT_DESC,
S.PO_REQ_DELIV_DATE,
S.PO_ITEM_NUMBER
FROM PDX_SAP_USER..VW_PO_SIZE S --- you can use .. insetead of .dbo.
JOIN ADI_USER_MAINTAINED..SCM_PO_Employee_Name E --- join the po to employee assigment table
ON S.PO_NUMBER = E.PO_NUMBER
JOIN PDX_SAP_USER..VW_PO_HEADER H
ON E.PO_NUMBER = H.PO_NUMBER
JOIN PDX_SAP_USER..VW_PO_ITEM I
ON E.PO_NUMBER = I.PO_NUMBER
JOIN PDX_SAP_USER..VW_MM_MATERIAL M
ON E.MATERIAL = M.MATERIAL
JOIN PDX_SAP_USER..vw_kd_BUSINESS_SEGMENT K
ON M.BUSINESS_SEGMENT_CODE = K.BUSINESS_SEGMENT_CODE
WHERE I.PO_BALANCE_QUANTITY > 0 ---exclude any fully received PO's
AND NOT EXISTS (SELECT * FROM VW_PO_ITEM I1 WHERE DEL_INDICATOR = 'L' AND I.PO_NUMBER = I1.PO_NUMBER)
GROUP BY S.PO_NUMBER,
E.TEAM_MEMBER_NAME,
H.PO_TYPE,
H.PO_ISSUE_DATE,
S.MATERIAL,
M.DESCRIPTION,
K.BUSINESS_SEGMENT_DESC,
H.PO_ORDERED_QUANTITY,
S.PO_REQ_DELIV_DATE,
S.PO_ITEM_NUMBER
HAVING COUNT(DISTINCT S.PO_REQ_DELIV_DATE) > 1
ORDER BY S.PO_NUMBER
Adding query that works along with the results:
SELECT E.TEAM_MEMBER_NAME [EMPLOYEE],
H.PO_TYPE,
CONVERT(VARCHAR(12),H.PO_ISSUE_DATE,101) [PO_ISSUE_DATE],
S.PO_NUMBER,
S.MATERIAL,
M.DESCRIPTION,
H.PO_ORDERED_QUANTITY [PO_QUANTITY], --- if you use SUM(S.PO_ORDERED_QUANTITY) - you get more results but wrong totals
K.BUSINESS_SEGMENT_DESC
FROM PDX_SAP_USER..VW_PO_SIZE S --- you can use .. insetead of .dbo.
JOIN ADI_USER_MAINTAINED..SCM_PO_Employee_Name E --- join the po to employee assigment table
ON S.PO_NUMBER = E.PO_NUMBER
JOIN PDX_SAP_USER..VW_PO_HEADER H
ON E.PO_NUMBER = H.PO_NUMBER
JOIN PDX_SAP_USER..VW_PO_ITEM I
ON E.PO_NUMBER = I.PO_NUMBER
JOIN PDX_SAP_USER..VW_MM_MATERIAL M
ON E.MATERIAL = M.MATERIAL
JOIN PDX_SAP_USER..vw_kd_BUSINESS_SEGMENT K
ON M.BUSINESS_SEGMENT_CODE = K.BUSINESS_SEGMENT_CODE
WHERE I.PO_BALANCE_QUANTITY > 0 ---exclude any fully received PO's
AND NOT EXISTS (SELECT * FROM VW_PO_ITEM I1 WHERE DEL_INDICATOR = 'L' AND I.PO_NUMBER = I1.PO_NUMBER)
GROUP BY S.PO_NUMBER,
E.TEAM_MEMBER_NAME,
H.PO_TYPE,
H.PO_ISSUE_DATE,
S.MATERIAL,
M.DESCRIPTION,
K.BUSINESS_SEGMENT_DESC,
H.PO_ORDERED_QUANTITY
HAVING COUNT(DISTINCT S.PO_REQ_DELIV_DATE) > 1
ORDER BY S.PO_NUMBER
Results:
EMPLOYEE PO_TYPE PO_ISSUE_DATE PO_NUMBER MATERIAL DESCRIPTION PO_QUANTITY BUSINESS_SEGMENT_DESC
------------------------------ ------- ------------- ---------- ------------------ ---------------------------------------- --------------------------------------- ----------------------------------------------------------------------------------------------------
Christopher Olson NB 01/19/2017 0282238419 CD7078 ESS 3S PANT WVN 2054 CORE APP MEN SPORT ADIDAS
Juan Gomez NB 02/23/2017 0282524995 S98775 ESS LIN P/O FT 103 CORE APP MEN SPORT ADIDAS
Christopher Olson NB 03/09/2017 0282598957 BK7410 ESS LGO T P SJ 619 ATHLETICS APP MEN ADIDAS
Juan Gomez NB 03/28/2017 0282706115 S97155 ESS LIN TIGHT 961 CORE APP WOMEN SPORT ADIDAS
Juan Gomez NB 09/21/2017 0283752965 CF8152 BOS LABEL 7900 ATHLETICS APP MEN ADIDAS
Julie Lange-May 12 10/02/2017 0283796594 DQ1421 WOVEN JACKET W 1020 ATHLETICS APP WOMEN ADIDAS
Kekai Ariola NB 10/10/2017 0283837426 AC7366 PW HU HOLI Tennis Hu MC 5655 STATEMENT FTW ADIDAS
Cody Lofquist NB 11/10/2017 0283944933 DB2061 PREDATOR TANGO 18.1 TR 1756 FOOTBALL FTW ADIDAS
Andrew Zapata 05 11/13/2017 0283961402 CG6440 NEMEZIZ 18.1 FG W 543 FOOTBALL FTW ADIDAS
Christopher Olson NB 11/20/2017 0283981666 CV7748 ASSITA 17 GK Y 1648 FOOTBALL APP GENERIC ADIDAS
Cody Lofquist NB 11/21/2017 0283984539 DB2165 COPA 18.1 FG 501 FOOTBALL FTW ADIDAS
Julie Lange-May NB 11/26/2017 0284043157 CE4368 I GRPHC STSET 1333 ORIGINALS APP KIDS ADIDAS
Trey Pflug NB 11/27/2017 0284048754 CQ3168 SOLAR BOOST M 3500 RUNNING FTW MEN ADIDAS
Dave Laws NB 11/28/2017 0284059045 DB2966 YEEZY 500 15334 YEEZY FTW ADIDAS
Dave Laws NB 11/28/2017 0284059047 DB2966 YEEZY 500 12584 YEEZY FTW ADIDAS
Christopher Olson NB 12/06/2017 0284094060 BJ9165 TASTIGO17 SHO W 7522 FOOTBALL APP GENERIC ADIDAS
Christopher Olson NB 12/06/2017 0284094212 BK0350 TIRO17 TRG PNTW 7091 FOOTBALL APP GENERIC ADIDAS
Cody Lofquist NB 12/08/2017 0284107301 DB2062 PREDATOR TANGO 18.1 TR 2110 FOOTBALL FTW ADIDAS
Trey Pflug NB 12/11/2017 0284115640 BC0674 SOLAR BOOST W 1752 RUNNING FTW WOMEN ADIDAS
Kim Moreland NB 12/12/2017 0284137355 DJ3033 D2M K SHT 1730 CORE APP WOMEN SPORT ADIDAS
Cody Lofquist NB 12/12/2017 0284141196 DB2126 PREDATOR TANGO 18.3 IN 1988 FOOTBALL FTW ADIDAS
Cody Lofquist NB 12/12/2017 0284141253 AQ0612 NEMEZIZ MESSI TANGO 18.3 TF 526 FOOTBALL FTW ADIDAS
Dave Laws NB 12/15/2017 0284170426 DB2966 YEEZY 500 2918 YEEZY FTW ADIDAS
Cody Lofquist NB 12/16/2017 0284174671 DB2248 X 18.1 FG 668 FOOTBALL FTW ADIDAS
Cody Lofquist NB 12/16/2017 0284174673 DB2039 PREDATOR 18.1 FG 489 FOOTBALL FTW ADIDAS
Christopher Olson ER 12/20/2017 0284207872 BS4250 TASTIGO17 SHO 404 FOOTBALL APP GENERIC ADIDAS
Ben Paul NB 12/19/2017 0284208137 CG0584 REAL A JSY 811 FOOTBALL APP LICENSED ADIDAS
Julie Lange-May NB 01/07/2018 0284316616 DN4273 UAS BEANIE 120 ORIGINALS APP MEN ADIDAS
Cody Lofquist NB 01/08/2018 0284319552 DB2063 PREDATOR TANGO 18.1 TR 2001 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464341 DB2214 X 18+ FG 582 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464343 DB2013 PREDATOR 18+ FG 2201 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464344 DB2072 NEMEZIZ 18+ FG 1467 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464346 DB2251 X 18.1 FG 620 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464348 DB2167 COPA 18.1 FG 1714 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464349 DB2089 NEMEZIZ MESSI 18.1 FG 988 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284464350 DB2040 PREDATOR 18.1 FG 2061 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/19/2018 0284465944 DB2001 PREDATOR 18.3 FG 7008 FOOTBALL FTW ADIDAS
Cody Lofquist NB 01/23/2018 0284489924 772109 SAMBA CLASSIC 419 FOOTBALL FTW ADIDAS
Andrew Zapata 05 02/02/2018 0284539184 DH3869 CLIMA 3.0 TEE 1853 ACTION SPORTS APP ADIDAS
Cody Lofquist NB 02/06/2018 0284550445 BB0571 Goletto VI FG J 5562 FOOTBALL FTW ADIDAS
Cody Lofquist NB 02/24/2018 0284666220 DM2092 MLS ASG OMB 424 FOOTBALL ACC HW ADIDAS
Christopher Olson NB 01/19/2018 0284666914 BP9111 D2M 3S SHORT 11811 CORE APP MEN SPORT ADIDAS
Cody Lofquist NB 02/27/2018 0284684097 019228 MUNDIAL TEAM 657 FOOTBALL FTW ADIDAS
Cody Lofquist NB 03/06/2018 0284704098 CD4683 GENERICWCBOX 80000 FOOTBALL ACC HW ADIDAS
Kekai Ariola NB 03/08/2018 0284728508 BB7619 Sobakov 1775 ORIGINALS FTW MEN ADIDAS
Kim Moreland NB 03/08/2018 0284730274 BP9733 ULT SS T 2557 TRAINING APP MEN ADIDAS
Kekai Ariola 05 03/27/2018 0284865999 B37532 EQT SUPPORT SK PK W 347 ORIGINALS FTW WOMEN ADIDAS
Kekai Ariola 05 03/27/2018 0284866000 B37545 EQT SUPPORT SK PK W 357 ORIGINALS FTW WOMEN ADIDAS
Kim Moreland NB 04/06/2018 0284914322 DH3591 Tech Tee 10042 TRAINING APP WOMEN ADIDAS
Cody Lofquist NB 04/10/2018 0284930265 CW5627 Pred FS JR MN 1651 FOOTBALL ACC HW ADIDAS
Kekai Ariola NB 04/10/2018 0284930449 B41794 PW TENNIS HU 315 ORIGINALS FTW MEN ADIDAS
(51 row(s) affected)
If you added HAVING clause recently then comment and check.
If not then change the INNER JOIN TO LEFT join from bottom to top one at a time and execute the query and check.
This way you can troubleshoot the issue easily.
Unless we have the sample data for all the tables you are used the query it will be difficult to answer.
WITH POsToReturn AS (
SELECT S.PO_NUMBER
FROM PDX_SAP_USER..VW_PO_SIZE S
JOIN PDX_SAP_USER..VW_PO_ITEM I
ON I.PO_NUMBER = S.PO_NUMBER
WHERE I.PO_BALANCE_QUANTITY > 0
GROUP BY S.PO_NUMBER
HAVING COUNT(DISTINCT S.PO_REQ_DELIV_DATE) > 1
AND COUNT(CASE WHEN I.DEL_INDICATOR = 'L' THEN 1 END) = 0
)
SELECT <your columns>
FROM POsToReturn P
JOIN PDX_SAP_USER..VW_PO_SIZE S
ON S.PO_NUMBER = P.PO_NUMBER
... <join the rest of the tables for the detail columns>
-- leave out the entire group by!
Or you could go with an approach like this:
with data as (
select
count(distinct S.PO_REQ_DELIV_DATE)
over (partition by S.PO_NUMBER) as rdd_count
<insert rest of main query>
)
select ... from data
where rdd_count > 1
order by S.PO_NUMBER;
As for understanding why, I think you've seen other queries where people added columns to a group by clause so they could get around a mysterious error message about non-aggregates. If not that then you've seen those systems that confusingly permit a non-standard behavior that gives results without erroring at all.
Usually what people want to accomplish is something like this: I'm grouping on Customer ID already but I want Customer Name in the results too. So they add that extra column to the 'group by' list and everything works fine. But if you think about it the reason is that the new column didn't change the groups at all since each Customer ID always has the same Customer Name anyway and it's ultimately just an easy way to get rid of the error. In your query that's not true though: you do have more than one date in all the groups you care about.
In my opinion it's better to use dummy aggregates like min(Customer Name) as CustomerName. Remember an aggregate function's purpose is collapsing multiple values into a single value. When necessary some systems will just pick a value at random, without warning you it did that. Many MySQL and Sybase developers got burned by this when they relied on this quirky behavior and/or never really learned how it's supposed to work.
Also remember that in general a group is a set of multiple rows collapsed into just one row. For count(distinct) to work it needed to see multiple dates across a single group. But that conflicts with your need to keep the output as separate rows.
Essentially the row by itself doesn't give you enough information to decide whether to keep it. I solved that by using a second query to figure a list of PO_Numbers meeting the criteria and then using that as a filter (via inner join.)
In the second example I used a window function instead, which lets you look outside each row without the row-collapsing behavior of group by. Both of the basically let you do what the having was intended to accomplish.
I don't understand what this order_by clause is doing and whether I need it or not:
select c.customerid, c.firstname, c.lastname, i.order_date, i.item, i.price from
items_ordered i, customers c
where i.customerid = c.customerid
group by c.customerid, i.item, i.order_date
order by i.order_date desc;
This produces this data:
10330 Shawn Dalton 30-Jun-1999 Pogo stick 28.00
10101 John Gray 30-Jun-1999 Raft 58.00
10410 Mary Ann Howell 30-Jan-2000 Unicycle 192.50
10101 John Gray 30-Dec-1999 Hoola Hoop 14.75
10449 Isabela Moore 29-Feb-2000 Flashlight 4.50
10410 Mary Ann Howell 28-Oct-1999 Sleeping Bag 89.22
10339 Anthony Sanchez 27-Jul-1999 Umbrella 4.50
10449 Isabela Moore 22-Dec-1999 Canoe 280.00
10298 Leroy Brown 19-Sep-1999 Lantern 29.00
10449 Isabela Moore 19-Mar-2000 Canoe paddle 40.00
10413 Donald Davids 19-Jan-2000 Lawnchair 32.00
10330 Shawn Dalton 19-Apr-2000 Shovel 16.75
10439 Conrad Giles 18-Sep-1999 Tent 88.00
10298 Leroy Brown 18-Mar-2000 Pocket Knife 22.38
10299 Elroy Keller 18-Jan-2000 Inflatable Mattress 38.00
10438 Kevin Smith 18-Jan-2000 Tent 79.99
10101 John Gray 18-Aug-1999 Rain Coat 18.30
10449 Isabela Moore 15-Dec-1999 Bicycle 380.50
10439 Conrad Giles 14-Aug-1999 Ski Poles 25.50
10449 Isabela Moore 13-Aug-1999 Unicycle 180.79
10101 John Gray 08-Mar-2000 Sleeping Bag 88.70
10299 Elroy Keller 06-Jul-1999 Parachute 1250.00
10438 Kevin Smith 02-Nov-1999 Pillow 8.50
10101 John Gray 02-Jan-2000 Lantern 16.00
10315 Lisa Jones 02-Feb-2000 Compass 8.00
10449 Isabela Moore 01-Sep-1999 Snow Shoes 45.00
10438 Kevin Smith 01-Nov-1999 Umbrella 6.75
10298 Leroy Brown 01-Jul-1999 Skateboard 33.00
10101 John Gray 01-Jul-1999 Life Vest 125.00
10330 Shawn Dalton 01-Jan-2000 Flashlight 28.00
10298 Leroy Brown 01-Dec-1999 Helmet 22.00
10298 Leroy Brown 01-Apr-2000 Ear Muffs 12.50
While if I remove the order_by clause completely, as in this query:
select c.customerid, c.firstname, c.lastname, i.order_date, i.item, i.price from
items_ordered i, customers c
where i.customerid = c.customerid
group by c.customerid, i.item, i.order_date;
I get these results:
10101 John Gray 30-Dec-1999 Hoola Hoop 14.75
10101 John Gray 02-Jan-2000 Lantern 16.00
10101 John Gray 01-Jul-1999 Life Vest 125.00
10101 John Gray 30-Jun-1999 Raft 58.00
10101 John Gray 18-Aug-1999 Rain Coat 18.30
10101 John Gray 08-Mar-2000 Sleeping Bag 88.70
10298 Leroy Brown 01-Apr-2000 Ear Muffs 12.50
10298 Leroy Brown 01-Dec-1999 Helmet 22.00
10298 Leroy Brown 19-Sep-1999 Lantern 29.00
10298 Leroy Brown 18-Mar-2000 Pocket Knife 22.38
10298 Leroy Brown 01-Jul-1999 Skateboard 33.00
10299 Elroy Keller 18-Jan-2000 Inflatable Mattress 38.00
10299 Elroy Keller 06-Jul-1999 Parachute 1250.00
10315 Lisa Jones 02-Feb-2000 Compass 8.00
10330 Shawn Dalton 01-Jan-2000 Flashlight 28.00
10330 Shawn Dalton 30-Jun-1999 Pogo stick 28.00
10330 Shawn Dalton 19-Apr-2000 Shovel 16.75
10339 Anthony Sanchez 27-Jul-1999 Umbrella 4.50
10410 Mary Ann Howell 28-Oct-1999 Sleeping Bag 89.22
10410 Mary Ann Howell 30-Jan-2000 Unicycle 192.50
10413 Donald Davids 19-Jan-2000 Lawnchair 32.00
10438 Kevin Smith 02-Nov-1999 Pillow 8.50
10438 Kevin Smith 18-Jan-2000 Tent 79.99
10438 Kevin Smith 01-Nov-1999 Umbrella 6.75
10439 Conrad Giles 14-Aug-1999 Ski Poles 25.50
10439 Conrad Giles 18-Sep-1999 Tent 88.00
10449 Isabela Moore 15-Dec-1999 Bicycle 380.50
10449 Isabela Moore 22-Dec-1999 Canoe 280.00
10449 Isabela Moore 19-Mar-2000 Canoe paddle 40.00
10449 Isabela Moore 29-Feb-2000 Flashlight 4.50
10449 Isabela Moore 01-Sep-1999 Snow Shoes 45.00
10449 Isabela Moore 13-Aug-1999 Unicycle 180.79
I'm not sure what the order_by is doing here and if it's having the intended effects.
It looks like it is ordering on i.ordered_date, but using string comparison rather than date comparison, which is why 30-Jun-1999 is placed before 29-Feb-2000. As a string "30-Jun-1999" > "28-Feb-2000", but as dates, the reverse is true.
Check the type of i.ordered_date in the items_ordered table - it should be datetime or similar - if it's varchar, then you will need to either change it to a date type, or cast the value to a date in the order-by clause. E.g.
order by CAST(i.order_date AS DATE) desc
You should always use proper DATETIME datatype to store dates