python - Loading a date in Numpy genfromtxt -


i'm trying import simple csv file numpy genfromtxt can't manage convert data of first column dates.

here code:

import numpy np datetime import datetime  str2date = lambda x: datetime.strptime(x, '%y-%m-%d %h:%m:%s')  data = np.genfromtxt('c:\\\\data.csv',dtype=none,names=true, delimiter=',', converters = {0: str2date}) 

i following error in str2date:

typeerror: must str, not bytes

the problem there many columns, i'd prefer avoiding specification of column types (which numerical).

the problem argument passed str2date of form b'%y-%m-%d %h:%m:%s'. these bytes, rightfully cannot parsed datetime object. solution problem quite simple though, should decode byte string utf-8 string:

str2date = lambda x: datetime.strptime(x.decode("utf-8"), '%y-%m-%d %h:%m:%s')


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -