Below is my code which is taking a long time to execute. How can I implement it in a list comprehension in Python to improve speed and efficiency?
buildings=[]
for bi in range(1449):
for si in range (16):
for m in range(3):
a= train[(train['building_id']==bi)&(train['site_id']==si)&(train['meter']==m)]
if not a.empty:
buildings.append(a.values)
1449*16*3is still69552, even if you hide the nested loops in an equivalent comprehension.