Abhishek Bhatia
Abhishek Bhatia

Reputation: 9796

TypeError histogram of time

I am trying to plot times by each hour

    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()

I get this error TypeError: 'len() of unsized object' in line 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) 

Edit: Fixed it by:

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

By I am incorrect hist. enter image description here

Edit 2: enter image description here

Upvotes: 1

Views: 4136

Answers (1)

rurp
rurp

Reputation: 1446

It looks like you are trying to plot strings as values. Try changing hour_list to:

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

Upvotes: 2

Related Questions