I would like to manipulate every row in df1:
print(df1)
| ID | Col1 | Col2 | ... | Col5 |
---------------------------------
| 123| A | B | ... | E |
| 456| A1 | B1 | ... | E1 |
and output to a new dataframe exactly like below:
| ID | Col_Num | Ans |
----------------------
| 123| Col1 | A |
| 123| Col2 | B |
| 123| Col3 | C |
| 123| Col4 | D |
| 123| Col5 | E |
| 456| Col1 | A1 |
| 456| Col2 | B1 |
| 456| Col3 | C1 |
| 456| Col4 | D1 |
| 456| Col5 | E1 |
I have created a function that does this if I give it a single row.
My question is how can I apply that function to every row. I believe a for loop will be inefficient if I have a large dataset of 1000 rows.
I have tried:
df1.apply(function, axis= 1)
df1.apply(lambda x: function, axis= 1)