I am trying to create a new data frame that compresses pre-existing columns from another data frame.
I am looking to turn something like this:
id | x1 | x2 | x3 | x4
-------------------------- ...
a | x1a | x2a | x3a | x4a
b | x1b | x2b | x3b | x4b
c | x1c | x2c | x3c | x4c
Into this:
id | z1 | z2
-------------------------------- ...
a | f1(x1a, x2a) | f2(x3a, x4a)
b | f1(x1b, x2b) | f2(x3b, x4b)
c | f1(x1c, x2c) | f2(x3c, x4c)
My current approach has been to continuously just append row by row to the new data frame. Like so:
for row in rows:
new_row_map = get_new_row_map(df_in, row)
df_out = df_out.append(new_row_map, ignore_index=True)
return df_out
I have been running this code for a couple hours now and it seems to be very inefficient. I was wondering if anyone had a quicker/more efficient approach here. Thanks!