猿问

python读取日期数据的问题

读取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'
海绵宝宝撒
浏览 676回答 2
2回答

BIG阳

python3 import numpy as np import matplotlib.dates as mdates data = '''code date open high low close change volume money traded_market_value market_value turnover adjust_price report_type report_date PE_TTM PS_TTM PC_TTM PB sh600004 2014/12/31 10.8 10.94 10.7 10.93 0.013915 19707899 213624420 12569500000 12569500000 0.017137303 12.13 2014/9/30 00:00 2014/10/30 00:00 12.88897481 2.317142523 7.472838539 1.561138066 sh600004 2014/12/30 11.18 11.26 10.65 10.78 -0.041778 25075183 273427007 12397000000 12397000000 0.021804507 11.96 2014/9/30 00:00 2014/10/30 00:00 12.71208613 2.285341989 7.370281078 1.53971296 ''' open('sh600004.csv','w').write(data) ddate,dopen = np.loadtxt('sh600004.csv', delimiter=' ', skiprows=1, converters={1:mdates.bytespdate2num('%Y/%m/%d')}, usecols= (1,2), unpack=True) print((ddate,dopen)) (array([ 735598., 735597.]), array([ 10.8 , 11.18]))
随时随地看视频慕课网APP

相关分类

Python
我要回答