【问题标题】:How to remove "₦" currency from column using Dataframe如何使用 Dataframe 从列中删除“₦”货币
【发布时间】:2020-06-12 21:08:35
【问题描述】:

我抓取了一个网站,在使用“pandas.dataframe()”查看数据后,我得到了下表,但我想从价格列中删除“₦”符号。这对我来说很难,因为计算机无法识别货币。我无法使用 replace()。这是我的代码;

URL= "https://www.weyn.com.ng/computing/"

web= requests.get(URL) 

soup= BeautifulSoup(web.content, "html.parser")

result= soup.find_all("article", {"class":"prd _fb col c-prd"})


computer= [computer_type.find("h3",{"class":"name"}).get_text() for computer_type in result]

price= [computer_price.find("div",{"class":"prc"}).get_text() for computer_price in result]


table= ({"comput": computer,
     "pric":price})
tab= pd.DataFrame(table)

print(tab)

输出

                                         comput       pric
0   Hp 15 Intel Pentium (500GB HDD, 8GB RAM) Windo...   ₦ 130290
1   Hp 15 Intel Pentium Dual Core 2.3ghz (4GB,500 ...   ₦ 122690
2   Hp 15 AMD Dual Core 500GB HDD 4GB RAM 15.6" WI...    ₦ 93290
3   Hp Notebook 15 Intel Core I3 (8GB RAM, 1TB HDD...   ₦ 156000

【问题讨论】:

    标签: pandas dataframe scrape


    【解决方案1】:

    你可以试试这个

    tab= pd.DataFrame(table)

    tab['pric'] = tab['pric'].replace({'₦':' '}, regex=True)

    【讨论】:

      【解决方案2】:

      你可以试试这个吗?

      tab.pric.str.extract('(\d+)')

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-03
        • 2018-05-26
        • 2014-03-16
        相关资源
        最近更新 更多