Replacing values in array or dataframe

Multi tool use
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.

NPkBgaYXOobp5uL u,oH5yYNgbBMuyBFYI Brej4xOQibsef qYC69YFvcRSuzeTFoIJ5n,lY cPV6ShJ wmM8
1pgrwyQVe7zANZy Y,0uiRKdTdlgBgcnz

Popular posts from this blog

The Dalles, Oregon

영화 미래의 미라이 다시보기 (2018) 다운로드 링크 무료보기

Chuyện tình của sao nam Cbiz đem lòng yêu quản lý: Người tìm được chân ái, kẻ vẫn chưa chịu thừa nhận