Barbiyong Barbiyong - 4 months ago 9x
Python Question

how to remove specific character in numpy?

I have the variable that get data from numpy for example

dataInput =, sep=',')
dataList['date'] = np.array(dataInput['Date'])

and my dataList['date'] format is '06/14/2016'
but i have some function that will use the format 06142016

I try to use some method but it have an error :

>>> date = dataList['date'][0]
>>> print (date)
>>> '06/14/2016'
>>> newDate = date.replace("/", "")
>>> AttributeError: 'numpy.float64' object has no attribute 'replace'

and also using strip

>>> newDate = date.strip( "/" )
>>> AttributeError: 'numpy.float64' object has no attribute 'strip'

so, it have any way to reformat my date.

>>> date = dataList['date'][0]
>>> print (date)
>>> '06/14/2016'
>>> newDate = SOME FUNCTION ()
>>> print (newDate)
>>> 06142016

Thank you.

I don't know how to create a best title for this problem so you can comment me and i will edit it :) sorry for unclear question


You could try to convert it to a string first and then call replace

my_string_date = str(date).replace('/', '')