My code as follows:
import numpy as np import matplotlib.dates as mdates stockFile = 'HistoricalQuotes.csv' dates, close = np.loadtxt(stockFile, delimiter=',', unpack=True, usecols=(0,1), \ converters = {0: mdates.strpdate2num('%Y-%m-%d')}) print("Dates = ", dates)
and the Traceback:
Traceback (most recent call last): File "/Users/zdlzdlxs/Documents/workspace/pynum_practice/part3/simplestats.py", line 7, in <module> converters = {0: mdates.strpdate2num('%Y-%m-%d')}) File "/Users/zdlzdlxs/Library/Python/3.6/lib/python/site-packages/numpy/lib/npyio.py", line 1024, in loadtxt items = [conv(val) for (conv, val) in zip(converters, vals)] File "/Users/zdlzdlxs/Library/Python/3.6/lib/python/site-packages/numpy/lib/npyio.py", line 1024, in <listcomp> items = [conv(val) for (conv, val) in zip(converters, vals)] File "/Users/zdlzdlxs/Library/Python/3.6/lib/python/site-packages/matplotlib/dates.py", line 287, in __call__ return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6])) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 559, in _strptime_time tt = _strptime(data_string, format)[0] File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_strptime.py", line 329, in _strptime raise TypeError(msg.format(index, type(arg))) TypeError: strptime() argument 0 must be str, not <class 'bytes'>
I've tried to find solutions in stackoverflow but failed. Could anyone help me to convert datetime correctly? Thanks a lot.