Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Index error help
#1
Hi,

I am extracting historic data from a scraping website using the following code. However, I get the error 'IndexError: index 228 is out of bounds for axis 0 with size 228' at random points for different ASIN values. Please find attached the code below.

import keepa import numpy as np import pandas as pd import csv import os import datetime import requests import asyncio import json import logging import time from functools import wraps from tqdm import tqdm import aiohttp cd = os.getcwd() print(cd) accesskey = 'fvjqmcuedgtkgvtt3bk71kpf605it36ofjv1r12vj3hilhbktahtib3810ti6hdt' #enter real access key here api = keepa.Keepa(accesskey) asins = ['0553819488'] products = api.query(asins) product = products[0] # Available keys print(products[0].keys()) ASIN = products[0]['asin'] domain = products[0]['domainId'] FBA = products[0]['fbaFees'] group = products[0]['productGroup'] height = products[0]['packageHeight'] length = products[0]['packageLength'] width = products[0]['packageWidth'] weight = products[0]['packageWeight'] itemweight = products[0]['itemWeight'] category = products[0]['rootCategory'] producttype = products[0]['productType'] #prime = products[0]['isPrimeExclusive'] amazonavail = products[0]['availabilityAmazon'] #salesrank = products[0]['salesRanks'] amprice = products[0]['data']['AMAZON'] usedprice = products[0]['data']['USED'] newprice = products[0]['data']['NEW'] newpricetime = products[0]['data']['NEW_time'] print('%20s %5s %5s %5s %5s ' % ('Date', 'Price', 'AmPrice', 'ASIN', 'Domain')) for i in range(1000): print(newpricetime[i], newprice[i], amprice[i], ASIN, domain)
As you can see from the code, though I am calling for the first 999 values the error is occuring at 228. Please help me on this issue.

Kind Regards,
Rohit.
Reply
#2
Why do you think that newpricetime, newprice and amprice have 1000 elements? As per the error message at least one of them has just 228 elements, thus max index is 227
Print the len of newpricetime, newprice and amprice and check for yourself
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyscript index error while calling input from html form pyscript_dude 2 2,654 May-21-2023, 08:17 AM
Last Post: snippsat
  I'm getting a String index out of range error debian77 7 5,195 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  Python Error List Index Out of Range abhi1vaishnav 3 5,957 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  Index error - columns vs non-column Vinny 3 7,645 Aug-09-2021, 04:46 PM
Last Post: snippsat
  How to resolve Index Error in my code? codify110 6 5,159 May-22-2021, 11:04 AM
Last Post: supuflounder
  index error surim 4 4,032 Dec-05-2020, 02:34 PM
Last Post: deanhystad
  I have an index error inline 76 but I write the program in a way that cant reach tha abbaszandi 2 3,371 Nov-13-2020, 07:43 AM
Last Post: buran
  when this error rise?index 28 is out of bounds for axis 0 with size 13 abbaszandi 1 6,232 Nov-10-2020, 08:46 PM
Last Post: deanhystad
  List index out of range error while accessing 2 lists in python K11 2 3,361 Sep-29-2020, 05:24 AM
Last Post: K11
  List index out of range error when attempting to make a basic shift code djwilson0495 4 5,022 Aug-16-2020, 08:56 PM
Last Post: deanhystad

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.