简体   繁体   中英

how to remove specific character in numpy?

I have the variable that get data from numpy for example

dataInput = pd.io.parsers.read_csv(url, 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

您可以尝试先将其转换为字符串,然后调用replace

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM