Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: unsupported operand type(s) for /: 'dict_values' and 'int'

this code doesn't run as expected in Python3 when I do my data-analysing practice.

The typeerror is "TypeError: unsupported operand type(s) for /: 'dict_values' and 'int'".

How should I solve it?

import numpy as np
# Summarize the data about minutes spent in the classroom
total_minutes = total_minutes_by_account.values()
total_minutes = np.array(total_minutes)
print('Mean:', np.mean(total_minutes))
print('Standard deviation:', np.std(total_minutes))
print('Minimum:', np.min(total_minutes))
print('Maximum:', np.max(total_minutes))
like image 616
Nemo.W Avatar asked Apr 27 '17 16:04

Nemo.W


1 Answers

total_minutes = total_minutes_by_account.values()

The variable total_minutes will be of type dict_values. To turn it into a list you need to wrap it in a list function like this:

total_minutes = list(total_minutes_by_account.values())
like image 185
Riddler Avatar answered Nov 07 '22 07:11

Riddler