How to map a function using multiple columns in pandas?

前端 未结 4 535
南旧
南旧 2021-02-02 11:59

I\'ve checked out map, apply, mapapply, and combine, but can\'t seem to find a simple way of doing the following:

I have a dataframe with 10 columns. I need to pass thre

4条回答
  •  面向向阳花
    2021-02-02 12:15

    If it is a really simple function, such as one based on simple arithmetic, chances are it can be vectorized. For instance, a linear combination can be made directly from the columns:

    df["d"] = w1*df["a"] + w2*df["b"] + w3*["c"]
    

    where w1,w2,w3 are scalar weights.

提交回复
热议问题