读取sh600004.csv文件,第二列是时间,格式是年-月-日。下面的代码变量ddate存储读出的时间。
import numpy as np
import matplotlib.dates as mdates
ddate,dopen = np.loadtxt('sh600004.csv', delimiter=',', skiprows=1,converters={0:mdates.strpdate2num('%Y-%m-%d')}, usecols= (1,2), unpack=True)
报错信息:
ValueError: could not convert string to float: b'2014-12-31'
According to the instructions of the numpy library, if the second column is a date, your parameter should be
converters={1:mdates.strpdate2num('%Y-%m-%d')}
python3