I have this DataFrame where the columns are coordinates (e.g. x1,y1,x2,y2...). The coordinate columns start from the 8th column (the previous ones are irrelevant for the question)
I have a larger example sample here, but here's a sample:
start_column = 8
df = pd.DataFrame(columns = ['x1','y1','x2','y2'],
data = [(0,0,1,0),(0,1,2,3),(-1,-2,None,None)])
for i in range(7):
df.insert(0,'c'+str(7-i),'x')
df
I want to create a new column in the DataFrame as a list of xy pairs, as in: df["coordinates"]=[[x1,y1],[x2,y2],[x3,y3]....]
What I've tried so far:
for row in df.iterrows():
for i in range(1,total_count_of_xy_rows):
df["coordinates"]=
df[["x{}".format(i),"y{}".format(i)]].values.tolist()
print(df)
Is there a better way to do this?