Guided Project: Prison Break > fetch_year() function TypeError

Hello,

Just getting started on the Helicopter project. Firstly, I’m not having trouble w/ the code, per se, but interpreting what is being asked of me.

However, I’m having issues with this seemingly easy part? Could someone please help? Thanks!

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

print(data[:3])

What I expected to happen:
I expected for Python to print 3 rows for me to see the first element in the first three rows.

What actually happened:

TypeError                                 Traceback (most recent call last)
<ipython-input-25-8a078f6cee5c> in <module>
      1 for row in data:
----> 2     date = fetch_year(row[0])
      3     row[0] = date

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

/dataquest/system/env/python3/lib/python3.8/re.py in findall(pattern, string, flags)
    237 
    238     Empty matches are included in the result."""
--> 239     return _compile(pattern, flags).findall(string)
    240 
    241 def finditer(pattern, string, flags=0):

TypeError: expected string or bytes-like object

By the looks of it, you are trying to run that code cell more than once.

The first time you ran the code, all the string dates in your data were converted to integers. The next time you try to run it, you get an error because fetch_year() expects a string.

You will have to run the previous code cells again to get back data with string dates and then run this code only once. When working with Jupyter Notebooks (or programming in general) it becomes somewhat important to try and keep track of what values you are modifying and when so as to avoid such issues.