TypeError时间直方图

时间:2015-09-08 07:45:18

标签: python pandas matplotlib histogram

我想按小时计划时间

    time_new=[x[:2]+":"+x[2:] for x in time_cleaned]        
    hour_list = [t[:2] for t in time_new]
    print hour_list
    numbers=[x for x in xrange(0,24)]
    labels=map(lambda x: str(x), numbers)
    plt.xticks(numbers, labels)
    plt.xlim(0,24)
    pdb.set_trace()
    plt.hist(hour_list)
    plt.show()

我在行TypeError: 'len() of unsized object'

中收到此错误plt.hist(hour_list)
pprint(time_new)
['09:00',
 '23:30',
 '19:05',
 '09:00',
 '01:00',
 '02:00',
 '19:00',
 '05:30',
 '04:00',
 '20:00',
 '23:30',
 '10:30',
 '20:00',
 '05:0',
 '21:30',
 '17:30',
 '04:55',
 '13:45',
 '08:40',
 '13:00',
 '06:00',
 '19:45',
 '09:00',
 '14:30',
 '09:00',
 '10:30',
 '23:07',
 '19:00',
 '23:40',
 '20:30',
 '19:30',
 '06:00',
 '05:30',
 '24:00',
 '20:30',
 '19:00',
 '15:05',
 '14:15',
 '19:20',
 '14:00',
 '15:15',
 '21:00']
(Pdb) 

编辑: 修正了:

hour_list = [int(t[:2]) for t in time_new]

我是错误的组织。 enter image description here

编辑2: enter image description here

1 个答案:

答案 0 :(得分:2)

看起来您正在尝试将字符串绘制为值。尝试将hour_list更改为:

hour_list = [int(t[:2]) for t in time_new]