I am using the function segmentMatch
in which I am sending two dataframes. I am using a for
loop through one dataframe and have some condition to check before I merge with another dataframe with the loop variable. It gives me perfect answer but because both dataframes were too big, it is too slow.
Is there any way I can improve the speed.
def segmentMatch(self, df, df_program):
df_result = []
for i, rview in df.iterrows():
df_tmp = []
df1 = []
df_tmp = df_program.ix[(df_program.iD == rview['id']) &
(rview['end_time'] >= df_program.START_TIME) &
(rview['start_time'] <= df_program.END_TIME)]
df1 = rview.to_frame().transpose()
tmp = pd.merge(df1, df_tmp,how='left')
df_result.append(tmp)
result = pd.concat(df_result, axis=0)
del(df1, df_tmp, tmp)
return result
Please help me. I am using Visual studio code and Python 3.6
Thanks in advance.