-2


for index, i in df.iterrows():
    temp=df.loc[df['security_code']==df['security_code'][index]]


this loop is to map dataframe which has same security code it results in data of similar security code with different dates

above for loop iterates each row in dataframe and dataframe consist of 27,000 rows which takes hours to iterate all the rows

problem is iteration through dataframe which contains huge number of rows takes lot of time and will this loop result in infinte loop?

  • please read [how-to-make-good-reproducible-pandas-examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Brown Bear Jun 20 '20 at 09:32
  • After you read it, please include a sample input and the expected output. – Roy2012 Jun 20 '20 at 10:36

1 Answers1

0

IIUC there is no need to use for loop to get rows with index matching 'security_code' column:

temp = df[df['security_code'] == df.index]

Your current code will actually overwrite temp as many time as there are indexes in your DataFrame.

Hugolmn
  • 1,530
  • 1
  • 7
  • 20