Running code on jupyter notebook

When i run this in dataquest code editor, it works fine but that same code doesnt work on jupyter notebook,how come?

Heres is the actual code:

bad_chars = ["(",")",“c”,“C”,".",“s”,"’", " "]

def strip_characters(date):
for char in bad_chars:
date = date.replace(char,"")
return date

stripped_test_data = [‘1912’, ‘1929’, ‘1913-1923’,
‘1951’, ‘1994’, ‘1934’,
‘1915’, ‘1995’, ‘1912’,
‘1988’, ‘2002’, ‘1957-1959’,
‘1955’, ‘1970’, ‘1990-1999’]
def process_date(date):
if ‘-’ in date:
split_date = date.split(’-’)
date_1 = split_date[0]
date_2 = split_date[1]
date = (int(date_1) + int(date_2))/2
date = round(date)
else:
date = int(date)

return date

processed_test_data =
for data in stripped_test_data:
date = process_date(data)
processed_test_data.append(date)
for row in moma:
date = row[6]
date = strip_characters(date)
date = process_date(date)
row[6] = date

HERE IS THE CODE ERROR:

29 for row in moma:
30 date = row[6]
—> 31 date = strip_characters(date)
32 date = process_date(date)
33 row[6] = date

in strip_characters(date)
3 def strip_characters(date):
4 for char in bad_chars:
----> 5 date = date.replace(char,"")
6 return date
7

AttributeError: ‘int’ object has no attribute ‘replace’

I frequently find two reasons for the disparity in running code in Jupyter vs dataquest.

  1. Difference in python or module versions
  2. Bugginess in Dataquest (it isn’t quite the same as running pure python)

Generally, I treat Jupyter as the one that I need to fix. Removing DQ from the equation, and just looking at your error. I think you are trying to use a string tool on an integer.

I was trying to create a function that removes character like $ and then converts strings to float or int but i keep getting this error.Any suggestions?

regex to strip the digits, convert to integer, then float?