I'm using this code, straight from the scikit-learn page. It creates a dictionary:
symbol_dict = {
'TOT': 'Total',
'XOM': 'Exxon',
'CVX': 'Chevron',}
symbols, names = np.array(symbol_dict.items()).T
But I get an error:
TypeError: iteration over a 0-d array
This code is straight from the example code, so I have no idea what's going wrong.
As user2357112 said, in Python 3 dict.items()
returns a dictionary view object rather than a list of key-value pairs (the difference is explained here). Wrapping it in list()
creates a list which is something NumPy can turn into an array:
np.array(list(symbol_dict.items()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With