dataquestio / solutions

Solutions for projects.
1.15k stars 1.56k forks source link

Problem with Guided Prison Break: Fetch_year function #160

Open MyNameisMatt1 opened 2 years ago

MyNameisMatt1 commented 2 years ago

Hello, I'm at mission 610 and I have a problem when I try replace the full date with just the year:

This is the code I'm using.

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

This is the error I get...

TypeError                                 Traceback (most recent call last)
<ipython-input-10-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
Abhishek-jha07 commented 1 year ago

Bro write this code instead for row in data: row[0] = fetch_year(row[0])