该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
版本是:3.7.0
代码是:
import numpy as np
from datetime import datetime
def datestr2num(s):
return datetime.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)
但是出现报错:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\pythons\numpy\date.py", line 7, in
(dates,close)=np.loadtxt('data.csv',delimiter=',',usecols=(1,6),converters={1:datestr2num},unpack=True)
File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\numpy\lib\npyio.py", line 1101, in loadtxt
for x in read_data(_loadtxt_chunksize):
File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\numpy\lib\npyio.py", line 1028, in read_data
items = [conv(val) for (conv, val) in zip(converters, vals)]
File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\numpy\lib\npyio.py", line 1028, in
items = [conv(val) for (conv, val) in zip(converters, vals)]
File "C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages\numpy\lib\npyio.py", line 1087, in tobytes_first
return conv(x.encode("latin1"))
File "C:\Users\Administrator\Desktop\pythons\numpy\date.py", line 5, in datestr2num
return datetime.datetime.strptime(s,'%d-%m-%Y').date().weekday()
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
不知道哪里出了问题