I have a data frame df that contains 15 columns (See below)
A_phase_1,A_phase_2,A_phase_3,A_phase_4,A_phase_5, B_phase_1,B_phase_2,B_phase_3,B_phase_4,B_phase_5, C_phase_1,C_phase_2,C_phase_3,C_phase_4,C_phase_5.
While retaining columns with phase_1 for example=A_phase_1, B_phase_1 and C_phase_1,
I want to programmatically do the following:
delete the columns containing
phase_2that is =A_phase_2,B_phase_2,C_phase_2replace the remainder column names
phase_nwithphase_n-1. for example,
all phase_3 become phase_2;
phase_4 --> phase_3;
phase_5 --> phase_4
So desired output should look like this :
A_phase_1,A_phase_2,A_phase_3,A_phase_4,
B_phase_1,B_phase_2,B_phase_3,B_phase_4,
C_phase_1,C_phase_2,C_phase_3,C_phase_4.
Thanks in advance!
@seaBean I got this error
