Issue
The below table having 1000 rows but here let's consider 3 rows:
Date | B | C |
---|---|---|
2022-07-24 | 12 | 1234 |
2021-02-01 | 34 | 6789 |
2020-04-30 | 23 | 4324 |
I want to multiply all values of B column with 2 and all values of C columns with 3 using apply function.
Solution
Try using df.mul
:
df.loc[:, ['B','C']] = df[['B','C']].mul([2,3])
Date B C
0 2022-07-24 24 3702
1 2021-02-01 68 20367
2 2020-04-30 46 12972
If set on using apply
, you could do:
df.loc[:, ['B','C']] = df[['B','C']].apply(lambda x: x.mul([2,3]), axis=1)
Evidently, this is unnecessary.
Answered By - ouroboros1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.