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

前端 未结 3 1378
不知归路
不知归路 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:57

    this should work, but honestly, OP figured it himself as well, so +1 OP :)

    df['result_col'] = [some_func(*var) for var in zip(*[df[col] for col in ['col_1', 'col_2',... ,'col_n']])]
    

提交回复
热议问题