Replacing values in array or dataframe

Multi tool use
I have a numpy array of values (simplified from a much larger dataset):
Which I want to turn into these values:
I have a lookup array, which I intended to use, but couldn't work out how to use it:
I couldn't work out a way to do this using numpy arrays, so I turned data into a Pandas dataframe:
And tried to convert the values using a dictionary:
This obviously didn't work, but also seems like a really clunky, terrible way of approaching the problem. There must be a way of looking up the lookup array rather than writing the dictionary. Does anyone have any pointers?
You need use numpy.vectorize in order to directly map values.
Output:
You array data
actually contains indices into the array lookup
, except that is starts at 1. You just ave to index it:
Maybe you can adapt your code to create directly the lookup2
array, but it depends on how you get your data.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.