【问题标题】:AttributeError: 'DataFrame' object has no attribute 'to_CSV' [closed]AttributeError:“DataFrame”对象没有属性“to_CSV”[关闭]
【发布时间】:2021-01-21 14:34:09
【问题描述】:

我正在尝试使用 df.to_CSV 将提取的 chrome 数据存储为 csv 格式

这是我的代码:

content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a',href=True, attrs={'class':'_13oc-S'}):
    name=a.find('div', attrs={'class':'_4rR01T'})
    price=a.find('div', attrs={'class':'_30jeq3 _1_WHN1'})
    rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'})
    products.append(name.text)
    prices.append(price.text)
    ratings.append(rating.text)
df = pd.DataFrame({'Product Name':products, 'Price':prices, 'Rating':ratings})
df.to_CSV(r'C:\Users\Krea\Documents\products.csv', index=False)

【问题讨论】:

  • 拼写为df.to_csv。

标签: python pandas dataframe selenium beautifulsoup


【解决方案1】:

区分大小写,应为df.to_csv(...)

【讨论】:

    【解决方案2】:

    Python 区分大小写。将最后一行更改为:

    df.to_csv(r'C:\Users\Krea\Documents\products.csv', index=False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 2021-12-17
      • 2017-01-24
      • 2018-10-10
      • 2019-08-18
      • 2021-01-20
      • 2020-05-16
      相关资源
      最近更新 更多