TypeError when using Matplotlib's strpdate2num with Python 3.2

前端 未结 3 2115
难免孤独
难免孤独 2020-12-11 07:38

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 i         


        
相关标签:
3条回答
  • 2020-12-11 08:02

    I had to remove the quotes from the example text. (using python3.4)

    ValueError: time data '"04.10.2012 08:15:27"' does not match format '%d.%m.%Y %H:%M:%S'
    
    0 讨论(0)
  • 2020-12-11 08:24

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

    0 讨论(0)
  • 2020-12-11 08:25

    Here is a workaround:

    import numpy as np
    import matplotlib.dates as mdates
    
    def bytedate2num(fmt):
        def converter(b):
            return mdates.strpdate2num(fmt)(b.decode('ascii'))
        return converter
    
    date_converter = bytedate2num("%d.%m.%Y %H:%M:%S")
    
    data = np.recfromtxt('example.txt',
                         comments='#',
                         delimiter=';',
                         names=('time', 't_ref', 't_s', 't_amb1', 't_amb2', 't_amb3'),
                         converters={'time': date_converter})
    
    0 讨论(0)
提交回复
热议问题