TypeError when using Matplotlib's strpdate2num with Python 3.2

前端 未结 3 2122
难免孤独
难免孤独 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: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})
    

提交回复
热议问题