Categories
Mastering Development

Split dataframe with all values in one row

I got the following dataframe which is created dynamically but saves all the relevant values into one row:

df

+----------------+----------------+----------------+----------------+
|       1        |       2        |       3        |       4        |
+----------------+----------------+----------------+----------------+
| a1, b1, c1, d1 | a2, b2, c2, d2 | a3, b3, c3, d3 | a4, b4, c4, d4 |
+----------------+----------------+----------------+----------------+

I need to have all a_i values in one row, all b’s etc (the columns are defined and constant):

+----+----+----+----+
| 1  | 2  | 3  | 4  |
+----+----+----+----+
| a1 | a2 | a3 | a4 |
| b1 | b2 | b3 | b4 |
| c1 | c2 | c3 | c4 |
| d1 | d2 | d3 | d4 |
+----+----+----+----+

Due to the circumstances that the number of different letters in df is changing from case to case I would need a dynamic solution which converts the df into the form above.

Leave a Reply

Your email address will not be published. Required fields are marked *