Aug-06-2020, 08:14 PM
list.index() is for finding an element in a 1D list. It won't descend into sub-lists that represent multi-dimensional arrays.
If you want to roll your own, you'll have to try to look for the data in each row separately. Something like:
If you want to roll your own, you'll have to try to look for the data in each row separately. Something like:
sampleArray = [['2020-07-22', 10256, 296, 57, 10481, 49, 389377, -10, -10, 15, 25650, 7007], ['2020-07-23', 12504, 292, 36, 10987, 51, 401881, 21, 20, 30, 25942, 7043], ['2020-07-24', 12213, 307, 41, 11294, 53, 414094, -2, -21, 45, 26249, 7084], ['2020-07-25', 9393, 186, 18, 10819, 50, 423487, -11, -24, 73, 26435, 7102], ['2020-07-26', 8918, 204, 14, 10344, 48, 432405, -5, -4, 45, 26639, 7116], ['2020-07-27', 9276, 208, 23, 10077, 47, 441681, -5, -8, 40, 26847, 7139], ['2020-07-28', 9482, 226, 26, 9928, 46, 451163, -8, -32, 0, 27073, 7165], ['2020-07-29', 10015, 211, 14, 9950, 46, 461178, -20, -12, 6, 27284, 7179], ['2020-07-30', 9048, 134, 16, 9724, 45, 470226, -26, -12, -21, 27418, 7195], ['2020-07-31', 9679, 97, 10, 9713, 45, 479905, 3, -23, -3, 27515, 7205], ['2020-08-01', 7227, 9, 1, 9092, 42, 487132, -19, -31, 15, 27524, 7206]] find_it = '2020-07-25' for row_index, row in enumerate(sampleArray): if find_it in row: print(f"[{row_index}][{row.index(find_it)}]")
Output:[3][0]
Otherwise, you could convert this to a numpy array and use numpy index.import numpy as np sampleArray = [['2020-07-22', 10256, 296, 57, 10481, 49, 389377, -10, -10, 15, 25650, 7007], ['2020-07-23', 12504, 292, 36, 10987, 51, 401881, 21, 20, 30, 25942, 7043], ['2020-07-24', 12213, 307, 41, 11294, 53, 414094, -2, -21, 45, 26249, 7084], ['2020-07-25', 9393, 186, 18, 10819, 50, 423487, -11, -24, 73, 26435, 7102], ['2020-07-26', 8918, 204, 14, 10344, 48, 432405, -5, -4, 45, 26639, 7116], ['2020-07-27', 9276, 208, 23, 10077, 47, 441681, -5, -8, 40, 26847, 7139], ['2020-07-28', 9482, 226, 26, 9928, 46, 451163, -8, -32, 0, 27073, 7165], ['2020-07-29', 10015, 211, 14, 9950, 46, 461178, -20, -12, 6, 27284, 7179], ['2020-07-30', 9048, 134, 16, 9724, 45, 470226, -26, -12, -21, 27418, 7195], ['2020-07-31', 9679, 97, 10, 9713, 45, 479905, 3, -23, -3, 27515, 7205], ['2020-08-01', 7227, 9, 1, 9092, 42, 487132, -19, -31, 15, 27524, 7206]] find_it = '2020-07-25' arr = np.array(sampleArray) print(np.where(arr == find_it))
Output:(array([3]), array([0]))