Reputation: 311
I have a large pandas DataFrame looking something like this :
a b c 1 2 3 4 ...
1 1 200 A T/T C/C ./. A/A ...
2 1 258 C ./. C/C T/T A/A ...
3 1 400 G G/G C/G ./. ./. ...
...
I want to replace every instance of "./." in any of the numbered columns with the respective entry in column c.
What would be the best way to do so?
I know it could be solved with iterating over every row, but is there a "better", faster solution?
Upvotes: 0
Views: 224
Reputation: 24314
Just make use of apply()
method:-
df=df.apply(lambda x:x.replace('./.',x['c']),axis=1)
Now if you print df
you will get your desired output:
a b c 1 2 3 4
1 1 200 A T/T C/C A A/A
2 1 258 C C C/C T/T A/A
3 1 400 G G/G C/G G G
Upvotes: 1