0

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)
erantdo
  • 685
  • 2
  • 9
  • 19

2 Answers2

3

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?

Community
  • 1
  • 1
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
2

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)):
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525