Grendel
Grendel

Reputation: 597

Change a value in a specific column (pandas)

I simply want to change a value in a specific colomn

gene     scaf    GC     other
gene1    3456    78      other1
gene2    7898    56      other 2
gene3    5667    23      other 3

etc and I want to add at each gene name the following number: _number1 and get:

gene             scaf    GC      other
gene1_number1    3456    78      other1
gene2            7898    56      other 2
gene3            5667    23      other 3

thanks all.

Upvotes: 1

Views: 95

Answers (1)

jezrael
jezrael

Reputation: 862481

You can add string by condition:

df.loc[df['gene'] == 'gene1', 'gene'] += '_number1'

print (df)
            gene  scaf  GC    other
0  gene1_number1  3456  78   other1
1          gene2  7898  56  other 2
2          gene3  5667  23  other 3

Upvotes: 1

Related Questions