My Code:
def clean_and_convert(date):
# check that we don't have an empty string
if date != "":
# move the rest of the function inside
# the if statement
date = date.replace("(", "")
date = date.replace(")", "")
date = int(date)
return date
for row in moma:
begin_date = row[3]
end_date = row[4]
birth_date = clean_and_convert(begin_date)
death_date = clean_and_convert(end_date)
row[3] = birth_date
row[4] = death_date
What I expected to happen:
With the if statement, it worked as instructed on dataquest but when I use the same code in Jupyter Notebook, it gave the error.
I tried to add float in
date = int(float(date)) function and it gives the similar error
What actually happened:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [9], in <cell line: 8>()
9 begin_date = row[3]
10 end_date = row[4]
---> 11 birth_date = clean_and_convert(begin_date)
12 death_date = clean_and_convert(end_date)
13 row[3] = birth_date
Input In [9], in clean_and_convert(date)
3 date = date.replace('(', '') # Move the rest of the function inside the if statement
4 date = date.replace(')', '')
----> 5 date = int(date)
6 return date
ValueError: invalid literal for int() with base 10: 'BeginDate'
While the submitted result is correct on dataquest, I am curious as to why Jupyter gives the error. Thank you!