So i have 2 lists the first comes from my dataset and contains dates-times in the format 'yyyy-mm-dd hh:mm', named times
. Example:
'2010-01-01 00:00', '2010-01-01 00:15', '2010-01-01 00:30', ...,
The other is a list of all the unique year month combinations, named year_and_month
. Example:
'2010-01', '2010-02', '2010-03', '2010-04',
So i try to extract all the indices of a year-month combination in the original dataset. I do that using the worst ways (new in python), namely
each_member_indices = []
for i in range(len(year_and_month)):
item_ind = []
for j in range(times.shape[0]):
if year_and_month[i] in times[j]:
item_ind.append(j)
each_member_indices.append(item_ind)
Now, this is a nuke for taking so much time to work. So i wanted to optimise it a bit and thus i was looking at some implementations such as Find intersection of two lists? and Python: Intersection of full string from list with partial string the problem being that
res_1 = [val for val in year_and_month if val in times]
yields an empty list, whereas
res_1 = [val for val in year_and_month if val in times[0]]
yields the first member at least.
Any thoughts?
EDIT:
I am only in need of the indices of the elements from the original dataset named times
corresponding the unique year-month pairs of the year_and_month
list. So as requested a sample output would be
[[0, 1, 2, 3,...],[925, 926, ...],...]
The first sublist contains the indices for the pair 2010-January, the second for the 2010-February and so on.