Reputation: 190
I have a pandas data frame like this:
ADP_4 G G G C G G G G G A
ADP_5 G G G A G G G G G A
ADP_3 G G G C G G G G G A
Actually, I want to know, how can I join every two columns together (except the first column) like this one:
ADP_4 GG GC GG GG GA
ADP_5 GG GA GG GG GA
ADP_3 GG GC GG GG GA
Upvotes: 0
Views: 45
Reputation: 150785
You can use groupby
along axis=1
:
# print `col_blocks` to see what it does
col_blocks = (np.arange(df.shape[1])+1)//2
df.groupby(col_blocks, axis=1).sum()
Output:
0 1 2 3 4 5
0 ADP_4 GG GC GG GG GA
1 ADP_5 GG GA GG GG GA
2 ADP_3 GG GC GG GG GA
Upvotes: 3