Ebay scraper 制作了一个数据框,但不能将这些数字用于未来的图形

Ebay scraper makes a dataframe but can´t use the numbers for future graphics

我正在尝试使用 python 为 ebay 制作一个简单的抓取工具,问题是我无法使用我制作的数据框。 我的代码:

import requests
from bs4 import BeautifulSoup
import pandas as pd
from csv import reader

url = "https://www.ebay.es/sch/i.html?_from=R40&_nkw=iphone&_sacat=0&LH_TitleDesc=0&_fsrp=1&Modelo=Apple%2520iPhone%2520X&_dcat=9355"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')

productslist = []
results = soup.find_all('div', {'class': 's-item__info clearfix'})
print(len(results))
for item in results:
    product = {
        'title': item.find('h3', {'class': 's-item__title'}),
        'soldprice': item.find('span', {'class': 's-item__price'})
    }
        
    productslist.append(product)

df =  pd.DataFrame(productslist)
df

但我得到的数据框是这样的: Dataframe

我希望能够使用价格数字,但我不能使用它,我想这是因为 dtype: object,我想知道如何转换,例如 [359, 00 EUR] 在 359,00 能够制作图形。 谢谢

要从 [...] 格式中删除“价格”,请使用 .text 方法。另外,请确保价格不是 None:

import requests
from bs4 import BeautifulSoup
import pandas as pd


url = "https://www.ebay.es/sch/i.html?_from=R40&_nkw=iphone&_sacat=0&LH_TitleDesc=0&_fsrp=1&Modelo=Apple%2520iPhone%2520X&_dcat=9355"
r = requests.get(url)
soup = BeautifulSoup(r.text, "html.parser")
productslist = []
results = soup.find_all("div", {"class": "s-item__info clearfix"})

for item in results:
    title = item.find("h3", {"class": "s-item__title"})
    price = item.find("span", {"class": "s-item__price"})
    if price is None:
        continue
    productslist.append({"title": title.text, "soldprice": price.text})


df = pd.DataFrame(productslist)
print(df)

输出:

                                               title                soldprice
0   APPLE IPHONE X 64 GB A+LIBRE+FACTURA+8 ACCESOR...               359,00 EUR
1               Apple iPhone X - 64GB - Plata (Libre)               177,50 EUR
2             Apple iPhone X - 64GB - Blanco  (Libre)               181,50 EUR
3                                       iphone x 64gb               240,50 EUR
4                                     Iphone x 256 gb               370,00 EUR
5         Apple iPhone X - 256GB - Space Gray (Libre)               400,00 EUR
6   Nuevo anuncioSMARTPHONE APPLE IPHONE X 64GB LI...               334,95 EUR
...
...