I am trying to map values from 1 Dataframe to another using the code below, it does the job but since the dataframes huge (2-3 million rows) it takes a lot of time to map these values. Is there a better and a more efficient way to write this code that can speed up the process?
for i in df.index:
fc2 = STP[(STP['SKU'] == df.iloc[i]['SKU']) & (STP['EFF_DATE'] <= df.iloc[i]['Date']) & ((STP['END_DTTIME'] >= df.iloc[i]['Date']))]['PRICE_TYPE']
if len(fc2.index) >0:
df['Price_Type'].iloc[i] = fc2.values.tolist()[0]
Any help would be highly appreciated.
df = {'Date': ['2020-10-24', '2020-10-24', '2020-10-20', '2020-10-24', '2020-10-24'], 'SKU': [125,3245,165158,1651651,16561]}
STP = {'SKU': [125,3245,3245,165158,165158,1651651,16561], 'EDD_DATE': ['2020-10-14','2020-10-14','2020-10-24','2020-09-28','2020-06-30','2020-10-14','2020-10-14'], 'END_DATE': ['2020-10-25','2020-10-23','2020-10-31','2020-10-31','2020-09-27','2020-10-25','2020-10-25'], 'PRICE_TYPE': ['abc', 'abc', 'bca', 'abc', 'bbc', 'abc', 'bca']}
final = {'Date': ['2020-10-24', '2020-10-24', '2020-10-20', '2020-10-24', '2020-10-24'], 'SKU': [125,3245,165158,1651651,16561], 'Price_Type': ['abc', 'bca', 'abc', 'abc', 'bca']}