Combine similar column values in pandas

Use Groupby.cumcount with df.loc and Series.ne:

In [938]: df.loc[df.groupby('A').cumcount().ne(0), 'A'] = ''

In [939]: df
Out[939]: 
       A   B   C
0  Apple  20  A1
1         30  A2
2         40  A3
3   Kiwi  20  K1
4         30  K2
5         10  K3

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top