Search code examples
pythonkeyerror

Python - KeyError: 14425L


When I use this code, it prints everything alright, and then gives me an error: KeyError: 14425L The code:

i = 0
while (i <= len(data)):
    print data.ix[i]['Params']
    i += 1

btw:

data.keys()
Out[67]: Index([u'Email Address', u'Hashed Email', u'Timestamp', u'Session Index', u'Event', u'Description', u'Version', u'Platform', u'Device', u'Params'], dtype=object)

Solution

  • Python list indices are 0 based, so len(data) is not a valid index.

    Use

    while (i < len(data)):
    

    instead.

    However, it looks like you are looping over a Pandas dataframe. You may want to review iterating row by row through a pandas dataframe and What is the most efficient way to loop through dataframes with pandas?