I have 2 dataframes like below :
df1 = pd.DataFrame(
{
'sentence': ['text1', 'text2', 'text3', 'text1', 'text1', 'text2'],
'label': ['abc', 'abc', 'abc', 'def', 'ghi', 'ghi']
}
)
df2 = pd.DataFrame(
{
'sentence': ['html_text1', 'html_text2', 'html_text3', 'html_text4'],
'label': ['abc', 'abc', 'def', 'ghi']
}
)
I want to iterate over the 2 dataframes and create a new dataframe. The condition for creating new dataframe is :
When label of df2 matches with label of df1, that record of df2 should be inserted above matching record of df1. So the final dataframe should look like :
P.S: I have not been able to work out the logic yet so I am not able to put sample code. However, I am trying to use dataframe.iterrows() to work on the above case.