Cannot export data to csv - raise ValueError("arrays must all be same length") ValueError: arrays must all be same length

0 votes
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import pandas as pd
import xlsxwriter

my_url = "https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2495737.m570.l1313.TR11.TRC2.A0.H1.XSamsung+Galaxy+.TRS1&_nkw=Samsung+Galaxy+&_sacat=0"

uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()

page_soup = soup(page_html, "html.parser")

containers = page_soup.findAll("div", {"class": "s-item__info clearfix"})

product = []
price = []
condition = []

# filename = "ebay2021.csv"
# f = open(filename, "w", encoding='utf-8')
# headers = "product_name, product_price, product_condition\n"
# f.write(headers)

for container in containers:
    brand = container.findAll('h3', {'class': 's-item__title'})
    product_name = brand[0].text

    price = container.findAll('span', {'class': 's-item__price'})
    product_price = price[0].text
    #
    condition = container.findAll("span", {"class": "SECONDARY_INFO"})
    product_condition = condition[0].text

    product.append(product_name)
    price.append(product_price)
    condition.append(product_condition)

    df = pd.DataFrame({'Product Name': product, 'Price': price, 'Rating': condition})
    df.to_csv('products.csv', index=False, encoding='utf-8')
Mar 21 in Python by Edureka
• 140 points
89 views

Hey, You can do this to avoid the error:

a = {'Product Name': product, 'Price': price, 'Rating': condition}
df = pd.DataFrame.from_dict(a, orient='index')
df.transpose()

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

In LightFM does the training set need to be the same size as the test set?

I would change the wording. Often in ML, ...READ MORE

answered Sep 21, 2018 in Python by charlie_brown
• 7,760 points
46 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Pyplot error "only size-1 arrays can be converted to Python scalars"

You can plot the chart by taking ...READ MORE

answered Jan 28, 2019 in Python by Omkar
• 69,000 points
4,443 views
0 votes
1 answer

Python convert all sheets of excel to csv

You will have to parse through the ...READ MORE

answered Feb 8, 2019 in Python by Omkar
• 69,000 points
956 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 755 views
0 votes
0 answers