Search code examples
evalnumpy-ndarray

get NameError when trying to apply eval on dict that one of the values is numpy array


"{'Probability': 1.0, 'StockChange': array([{'Taken': False...\n dtype=object)}}"

I'm trying to convert the above dict that was converted to string (and was corrupted) while importing from a csv file.

The problem is that this dictionary conatins different types of elements and it seems like the fact that one of the values is numpy array is preventing me to apply the function eval on this string and convert it back to dict like it should be When I'm trying to apply the function I get the following error: NameError: name 'array' is not defined

Whan can I do to overcome it?


Solution

  • It should work, make sure that you imported numpy arrays correctly with from numpy import array before your eval.