Reputation: 83
I have two series sr1 and sr2:
sr1 = pd.Series([1, 2, 3, 4, 5])
sr2 = pd.Series([6, 0, 0, 4 ,9])
I want to update series 1 i.e sr1 from sr2. If sr2 is 0 then same value should be updated in sr1 for same index. I want below output :
sr1
0 1
1 0
2 0
3 4
4 5
Upvotes: 1
Views: 101
Reputation: 3025
if you use series, You can use the following code:
sr1 = pd.Series([1, 2, 3, 4, 5])
sr2 = pd.Series([6, 0, 0, 4 ,9])
sr1=sr1.mask(sr2==0,0)
Upvotes: 0