我試圖從CSV文件加載數據,並將一列與日期轉換爲一週數。我得到下面提到TypeError
:將loadtxt列轉換爲星期幾:TypeError:strptime()參數1必須是str,而不是字節
import numpy as np
from datetime import datetime
def datestr2num(s):
return datetime.strptime(s, "%d-%m-%Y").date().weekday()
dates, close = np.loadtxt(
'data.csv', delimiter=',', usecols=(1,6),
converters={1: datestr2num}, unpack=True)
print("Dates =", dates)
錯誤:
TypeError: strptime() argument 1 must be str, not bytes
我試圖關於Python 3.5.2 -Anaconda定製(64位)
'loadtxt'不返回一個元組? https://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html – ppasler