Dataframe Apply method to return multiple elements (series)

前端 未结 4 400
粉色の甜心
粉色の甜心 2021-01-19 21:15
import pandas as pd

Let\'s say I have a dataframe like so:

df = pd.DataFrame({\"a\":range(4),\"b\":range(1,5)})
         


        
4条回答
  •  旧时难觅i
    2021-01-19 22:07

    df["e"], df["f"] = zip(*df.apply( lambda x: divideAndMultiply(x["a"],2) , axis =1))
    

    Should do the trick.

    (I show this example so you can see how to use multiple columns as the input to create multiple new columns)

提交回复
热议问题