【问题标题】:Why can't Pandas Remove Unknown Characters from Row Data?为什么 Pandas 不能从行数据中删除未知字符?
【发布时间】:2021-03-01 15:01:37
【问题描述】:

大家好,所以我正在抓取一个鞋类网站,并获得了所有链接和图片及其各自的名称和品牌。

我已将它们保存在 Excel 文件中,并且我还借助 excel 删除了未知字符,但是当我使用 jupyter Notebooks 将其加载到 pandas 中时,下载停止在第 83 号,因为它们的名称是 \ .

我尝试使用 str.replace 方法,但它给了我一个 EOL 解析错误

这是我的代码和相应的 Excel 文件供参考:)

import pandas as pd
import requests

Final1 = pd.read_excel("VNV.xlsx")
Final1.index+=1

a = Final1.index.tolist()

Brand = Final1["Brand"].tolist()

Title = Final1["Title"].str.split().str.join(" ").tolist()

Images = Final1["Images"].tolist()

s = requests.Session()

for i,b,n,l in zip(a,Brand,Title,Images):
    r = s.get(l).content
    with open("Images//" + f"{i}-{b}-{n}.jpg","wb") as f:
              f.write(r)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-3-13d7c7daa564> in <module>
      3 for i,b,n,l in zip(a,Brand,Title,Images):
      4     r = s.get(l).content
----> 5     with open("Images//" + f"{i}-{b}-{n}.jpg","wb") as f:
      6               f.write(r)

OSError: [Errno 22] Invalid argument: 'Images//83-ASICS-GEL-LYTE III OG "30TH ANNIVERSARY" \'WHITEFLASH CORAL\'.jpg'

EXCEL 文件(Google Drive 链接):

Excel File

【问题讨论】:

    标签: python arrays pandas web-scraping python-requests


    【解决方案1】:

    我终于找到了答案,我的名字多次被双引号,

    一个名字中的例子:"s" f "g" "j"

    感谢 excel,因此删除了引号,并且所有 250 张图片都已下载。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多