Reputation: 1593
Is there a good way to shorten this:
df.a = df.a / 2
df.b = df.b / 2
df.c = df.c / 2
According to this, something like
df[['A','B','C']] = df[['A', 'B','C']].apply(lambda a: a / 2)
should be avoided.
Upvotes: 1
Views: 50
Reputation: 11
Try something like this to take advantage of vectorization.
df[['A','B','C']]/2
Upvotes: 1
Reputation: 1383
You can easily do it like this
df[['A','B','C']] = df[['A','B','C']]/2
Upvotes: 2