Dataframe list comprehension “zip(…)”: loop through chosen df columns efficiently with just a list of column name strings

前端 未结 3 1377
不知归路
不知归路 2021-01-21 12:22

This is just a nitpicking syntactic question...

I have a dataframe, and I want to use list comprehension to evaluate a function using lots of columns.

I know I c

3条回答
  •  野性不改
    2021-01-21 12:50

    As mentioned in the comments above, you should use apply instead:

    df['reult_col'] = df.apply(lambda x: some_func(*tuple(x.values)), axis=1)
    

提交回复
热议问题