I have text file in the following shape:
filepath,x1,y1,x2,y2,class_name
000005.jpg,253,165,372,264,9
000005.jpg,67,5,374,244,9
000005.jpg,295,241,299,194,9
000005.jpg,312,277,220,186,9
000007.jpg,500,141,330,50,7
000009.jpg,270,69,330,172,13
000009.jpg,229,150,284,141,1
Where each object in the same image take a row, I want a python code (using csv or txt file) to merge the objects for each image into single row, so the expected output would be as follow:
000005.jpg,253,165,372,264,9 67,5,374,244,9 295,241,299,194,9 312,277,220,186,9
000007.jpg,500,141,330,50,7
000009.jpg,270,69,330,172,13 229,150,284,141,1
This is the code I am using so far but it gives me an error;
## convert it to dataframe
import pandas as pd
df = pd.DataFrame(second_col, columns=['filepath','x1','y1','x2','y2','class_name'])
list=[]
for index, row in df.iterrows():
item2=row['filepath'][index+1]
if item2==row['filepath']:
list.append(item2)
This gives me the following error:
IndexError: string index out of range
Any suggestions on how is this possible using python?