I have a DataFrame that contains words and their bounding boxes on an image, the image is that of a table
df_text = pd.DataFrame({
'words': ['Hello', 'world', 'nice day', 'have a', 'Greeting_1', 'Greeting_2'],
'left': [1097, 1099, 258, 259, 1096, 260],
'top': [1248, 1249, 1156, 1153,1200,250],
'right': [1154, 1156, 615, 614, 1150, 610],
'bottom': [1269, 1271, 1175, 1172, 1255, 1170]
})
Which looks like this:
Words left top right bottom
hello 1097 1248 1154 1269
world 1099 1249 1156 1271
nice day 258 1156 615 1175
have a 259 1153 614 1172
Greeting_1 1096 1200 1150 1255
Greeting_2 260 250 610 1170
I now want to create a DataFrame that mimics the original image which looks like this:
Greeting_1 Greeting_2
hello Have a
world nice day
So basically I want to select the column values of words that come under Greeting_1 and make a new column out of it and want the same for Greeting_2. Generally the left, top, right, bottom values of Greeting_1 and Greeting_2 are lower than the words that come under it. Greeting_1 and Greeting_2 can appear in any order in the original dataframe.
Would appreciate some help in solving this problem.