gpt4 book ai didi

python - 匹配表中的行

转载 作者:行者123 更新时间:2023-11-30 23:01:31 24 4
gpt4 key购买 nike

我正在抓取这个维基百科页面:

https://en.wikipedia.org/wiki/List_of_shopping_malls_in_the_South_Florida_metropolitan_area

并从表中获取数据,如下所示:

Location = response.xpath('//*[@id="mw-content-text"]/table/tr/td[2]/a/text()').extract()[0]

Name = response.xpath('//*[@id="mw-content-text"]/table/tr/td[1]/a/text()').extract()

一旦我有了它,计划是将这些列表添加到数据框中。问题是最后我得到:

len(Name)
40

 len(Location)
47

这是因为位置列中的某些行有多个元素,例如第三列中的元素:椰林,迈阿密在那里我得到了元素。

最佳答案

您可以使用read_html并且 dfdfs 的第一个 df:

df = pd.read_html('https://en.wikipedia.org/wiki/List_of_shopping_malls_in_the_South_Florida_metropolitan_area',
header=0 )[0]
print df

Name Location
0 Aventura Mall Aventura
1 Bal Harbour Shops Bal Harbour
2 Bayside Marketplace Downtown Miami
3 Boynton Beach Mall Boynton Beach
4 CityPlace West Palm Beach
5 CocoWalk Coconut Grove, Miami
6 Coral Square Coral Springs
7 Dadeland Mall Kendall
8 Dolphin Mall Sweetwater
9 Downtown at the Gardens Palm Beach Gardens
10 The Falls Kendall
11 Galeria International Mall Downtown Miami
12 The Galleria at Fort Lauderdale Fort Lauderdale
13 The Gardens Mall Palm Beach Gardens
14 The Grand Doubletree Shops Downtown Miami
15 Las Olas Riverfront Fort Lauderdale
16 Las Olas Shops Fort Lauderdale
17 Lincoln Road Mall Miami Beach
18 Loehmann's Fashion Island Aventura
19 Mall of the Americas Miami
20 The Mall at 163rd Street North Miami Beach
21 The Mall at Wellington Green Wellington
22 Miami International Mall Doral
23 Miracle Marketplace Miami
24 Metrofare Shops & Cafe Government Center, Downtown Miami
25 Pembroke Lakes Mall Pembroke Pines
26 Pompano Citi Centre Pompano Beach
27 Sawgrass Mills Sunrise
28 Seminole Paradise Hollywood
29 The Shops at Fontainebleau Miami Beach
30 The Shops at Mary Brickell Village Brickell, Miami
31 The Shops at Midtown Miami Midtown Miami
32 The Shops at Pembroke Gardens Pembroke Pines
33 The Shops at Sunset Place South Miami
34 Southland Mall Cutler Bay
35 Town Center at Boca Raton Boca Raton
36 The Village at Gulfstream Park Hallandale Beach
37 Village of Merrick Park Coral Gables
38 Westfield Broward Plantation
39 Westland Mall Hialeah

关于python - 匹配表中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com