سؤال

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)
هل كانت مفيدة؟

المحلول

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?

نصائح أخرى

You are accessing index past the last one. Maximum index of a list is len(data) - 1.

while (i <= len(data)):

should be:

while (i < len(data)):
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top