python date2num_将Matplotlib的strpdate2num与Python 3.2一起使用时发生TypeError

In my current project I want to read some experimental data from a text file into Python using the following code:

import numpy as np

from matplotlib.dates import strpdate2num

data = np.recfromtxt('example.txt',

comments='#',

delimiter=';',

names=('time', 't_ref', 't_s', 't_amb1', 't_amb2', 't_amb3')

,converters={'time': strpdate2num('"%d.%m.%Y %H:%M:%S"')}

)

with example.txt looking like

"04.10.2012 08:15:27";14.4;16;12.78;12.65;12.52

"04.10.2012 08:15:37";14.4;16;12.78;12.65;12.5

"04.10.2012 08:15:47";14.4;16;12.78;12.62;12.5

"04.10.2012 08:15:57";14.4;15.9;12.78;12.65;12.52

...

In Python 2.7, all is well, but when I try to transfer the code in 3.2, I get a TypeError from strpdate2num() saying

TypeError: strptime() argument 0 must be str, not

I am fairly new to Python, but my theory is that NumPy somehow stores the time-array internally as byte instead of string, which collides with the stricter handling of both since Python 3.

Long story short, do you have any idea what might be the cause how to fix that?

解决方案

The workaround of unutbu work perfectly fine. Meanwhile it seems that the issue has been addressed. Using bytespdate2num() instead of strpdate2num() works for me.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值