I have a dataframe having 54 columns and 100000 rows I need to run sql query using row values in where condition .Is there a faster way to acheive that .this is what I have done
My code:
def GetTMIDCMID(ClientFileDf):
try:
CMCPCodedf_lst=[]
NewColumnName = ['TCM_TM_ID','TCM_CM_ID']
col_one_list = ClientFileDf['tradingmemberpan'].tolist()
col_one_list = ['' if pd.isna(x) else x for x in col_one_list]
for i in range(len(col_one_list)):
Query="select OFF_TM_ID,OFF_CM_ID from UCIDBA.COR_OFF_VW where OFF_TM_PANNO ='" + col_one_list[i] +"'"
df_CMCPCodeDF = pd.read_sql(Query, con=connection)
df_CMCPCodeDF_lst=df_CMCPCodeDF.values.tolist()
CMCPCodedf_lst.extend(df_CMCPCodeDF_lst)
CMCPCodedf=pd.DataFrame(CMCPCodedf_lst)
CMCPCodedf.columns = NewColumnName
return CMCPCodedf
except Exception as ex:
logging.exception("CollateralValidation:Utility-> GetTMIDCMID : |")
print(ex)
return False
This is just one of the functions .There are some cases where multiple where clause condition is implemented .dataframe is passed as an argumnent of the function. Thanks .