'Columns manipulation - python

Here is my dataset:

  •    COL_1  COL_2   COL_3   COL_4   COL_5 COL_8 COL_9
       A      col2    col3    col4    col5
       B      col2    col3    col4    col5
       C      col2    col3    col4    col5
    

I need to move pairs of columns (COL_2 , COL_3 and then COL_4, COL_5) to COL_8 and COL_9 and copy the content of the 1st column (COL_1):

  •    COL_1  COL_8   COL_9
      A       col2    col3
      B       col2    col3
      C       col2    col3
      A       col4    col5
      B       col4    col5
      C       col4    col5
    

How can I do it using Python? Do I need to use loop or are there easier ways to do so?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source