Mar-26-2024, 08:39 AM
agree with @deanhystad
For instance, if the goal is to recover data per type, I would imagine the following if you can use 2 arrays (possible?):
For instance, if the goal is to recover data per type, I would imagine the following if you can use 2 arrays (possible?):
import numpy as np Array1 = np.array([['2024-03-22', 71.0, 'ceh'], ['2024-03-23', 63.0, 'abc'], ['2024-03-24', -50.6, 'zzzzzzz'], ['2024-03-25', 13.8, 'lkj'], ['2024-03-26', 05.2, 'dsfdssss'], [935.2, 'hgjhg', '2024-03-27'] ]) TypeArray = np.array([['datetime64[D]', 'float64', 'string'], ['datetime64[D]', 'float64', 'string'], ['datetime64[D]', 'float64', 'string'], ['datetime64[D]', 'float64', 'string'], ['datetime64[D]', 'float64', 'string'], ['float64', 'string', 'datetime64[D]'] # !!!!!!!!!!!!!! ]) NumberOfTypes = np.unique(TypeArray) # results are stored in a dictionary PER type but you can proceed differently RecoveringDictionary = {} for ntype in NumberOfTypes: Index = np.where(TypeArray == ntype) Extract = Array1[Index] if ntype == 'float64': Extract = Extract.astype(np.float64) # if ntype == 'datetime64[D]': Extract = Extract.astype(np.datetime64) RecoveringDictionary.update({ ntype: Extract, }) # print results for ntype in NumberOfTypes: print(f"{ntype} = {RecoveringDictionary[ntype]}\n")
Output:datetime64[D] = ['2024-03-22' '2024-03-23' '2024-03-24' '2024-03-25' '2024-03-26' '2024-03-27']
float64 = [ 71. 63. -50.6 13.8 5.2 935.2]
string = ['ceh' 'abc' 'zzzzzzz' 'lkj' 'dsfdssss' 'hgjhg']