Index error from Helicopter escape guided project

Screen Link:

My Code:

for row in data:
    row[0] = fetch_year(row[0])

What I expected to happen:

What actually happened:

IndexError                                Traceback (most recent call last)
<ipython-input-16-9a5dafceb371> in <module>
      1 for row in data:
----> 2     row[0] = fetch_year(row[0])
      3 print(data[:3])

~/notebook/ in fetch_year(date_string)
     11 def fetch_year(date_string):
---> 12     return int(re.findall("\d{4}", date_string)[0])
     14 def barplot(list_of_2_element_list):

IndexError: list index out of range

Please I need help on the error message. I’ve checked on similar projects and executed but still giving me same index error.Preformatted text
Basics.ipynb (9.9 KB)

1 Like


There’s probably something wrong with your data.

It would be helpful if you upload your notebook in your post so we can have a look at your whole code. Here’s a guide on how to do so.

1 Like

Thanks for your reply. I tried attaching the notebook but it’s showing not a valid file




Is the file an .ipynb file?

Yes sir

Hmm…can you screenshot the name of the file and its extension?

Yeah, that is a .json file.

After you’ve downloaded and extracted the file from Dataquest, there should be a Basics.ipynb file. Upload that if you can find it.

Maybe you can try renaming that file as Basics.ipynb and see if you are able to upload that.

Thanks. Let me check

I couldn’t find an additional file. Edited the file name to Basic.ipynb and still showing same error during attachment

I see. Weird.

If you’re willing, I can guide you to do it step-by-step just to see if there’s something wrong when you downloaded the file.

Sure I’m willing sir


Let’s start by downloading the notebook again from the project page: Learn data science with Python and R projects.

Click “download” on the top right next to the “refresh” button, and you should receive a .tar folder. It would probably be in the downloads folder.

Though, I’m not sure if it works with a phone. I tried but nothing was downloaded. A desktop or laptop is ideal.

Alright. Let me use a laptop to log in

I have added the file to the post
Basics.ipynb (9.9 KB)

Click here to view the jupyter notebook file in a new tab

1 Like

Nice! Let me have a look.

1 Like

Okay, here’s the source of the issue:

index = 0
for row in data:
    data = row[:-1]
    index += 1

You got almost everything right, except for one line. I recommend reviewing the instruction again, especially the following line:

  • Assign row without its last element to data[index].

What you’re doing above is assigning row[:-1] to the whole data instead of assigning it to data[index]. You’ll need to modify your data so that it refers to the element inside the data with index as the element’s index, and not the whole data (if that makes sense).

Try changing that and see if it works or not.


Yes it worked perfectly. :slightly_smiling_face::+1: Thanks for the observation and correction.

1 Like

No worries. I’m glad that it worked.

We all get stuck one way or another, so feel free to make a post in the forum if you find yourself stuck on something else.